@@ -12,108 +12,108 @@ |
||
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 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Payment form submission fees class |
@@ -29,10 +29,10 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @param GetPaid_Payment_Form_Submission $submission |
31 | 31 | */ |
32 | - public function __construct( $submission ) { |
|
32 | + public function __construct($submission) { |
|
33 | 33 | |
34 | 34 | // Process any existing invoice fees. |
35 | - if ( $submission->has_invoice() ) { |
|
35 | + if ($submission->has_invoice()) { |
|
36 | 36 | $this->fees = $submission->get_invoice()->get_fees(); |
37 | 37 | } |
38 | 38 | |
@@ -40,14 +40,14 @@ discard block |
||
40 | 40 | $data = $submission->get_data(); |
41 | 41 | $payment_form = $submission->get_payment_form(); |
42 | 42 | |
43 | - foreach ( $payment_form->get_elements() as $element ) { |
|
43 | + foreach ($payment_form->get_elements() as $element) { |
|
44 | 44 | |
45 | - if ( 'price_input' == $element['type'] ) { |
|
46 | - $this->process_price_input( $element, $data ); |
|
45 | + if ('price_input' == $element['type']) { |
|
46 | + $this->process_price_input($element, $data); |
|
47 | 47 | } |
48 | 48 | |
49 | - if ( 'price_select' == $element['type'] ) { |
|
50 | - $this->process_price_select( $element, $data ); |
|
49 | + if ('price_select' == $element['type']) { |
|
50 | + $this->process_price_select($element, $data); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | } |
@@ -60,21 +60,21 @@ discard block |
||
60 | 60 | * @param array $element |
61 | 61 | * @param array $data |
62 | 62 | */ |
63 | - public function process_price_input( $element, $data ) { |
|
63 | + public function process_price_input($element, $data) { |
|
64 | 64 | |
65 | 65 | // Abort if not passed. |
66 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
66 | + if (empty($data[$element['id']])) { |
|
67 | 67 | return; |
68 | 68 | } |
69 | 69 | |
70 | - $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
71 | - $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
70 | + $amount = (float) wpinv_sanitize_amount($data[$element['id']]); |
|
71 | + $minimum = empty($element['minimum']) ? 0 : (float) wpinv_sanitize_amount($element['minimum']); |
|
72 | 72 | |
73 | - if ( $amount < $minimum ) { |
|
74 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), $minimum ) ); |
|
73 | + if ($amount < $minimum) { |
|
74 | + throw new Exception(sprintf(__('The minimum allowed amount is %s', 'invoicing'), $minimum)); |
|
75 | 75 | } |
76 | 76 | |
77 | - $this->fees[ $element['label'] ] = array( |
|
77 | + $this->fees[$element['label']] = array( |
|
78 | 78 | 'name' => $element['label'], |
79 | 79 | 'initial_fee' => $amount, |
80 | 80 | 'recurring_fee' => 0, |
@@ -88,27 +88,27 @@ discard block |
||
88 | 88 | * @param array $element |
89 | 89 | * @param array $data |
90 | 90 | */ |
91 | - public function process_price_select( $element, $data ) { |
|
91 | + public function process_price_select($element, $data) { |
|
92 | 92 | |
93 | 93 | // Abort if not passed. |
94 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
94 | + if (empty($data[$element['id']])) { |
|
95 | 95 | return; |
96 | 96 | } |
97 | 97 | |
98 | - $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
99 | - $selected = wpinv_parse_list( $data[ $element['id'] ] ); |
|
98 | + $options = getpaid_convert_price_string_to_options($element['options']); |
|
99 | + $selected = wpinv_parse_list($data[$element['id']]); |
|
100 | 100 | $total = 0; |
101 | 101 | |
102 | - foreach ( $selected as $price ) { |
|
102 | + foreach ($selected as $price) { |
|
103 | 103 | |
104 | - if ( ! isset( $options[ $price ] ) ) { |
|
105 | - throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
104 | + if (!isset($options[$price])) { |
|
105 | + throw new Exception(__('You have selected an invalid amount', 'invoicing')); |
|
106 | 106 | } |
107 | 107 | |
108 | - $total += (float) wpinv_sanitize_amount( $price ); |
|
108 | + $total += (float) wpinv_sanitize_amount($price); |
|
109 | 109 | } |
110 | 110 | |
111 | - $this->fees[ $element['label'] ] = array( |
|
111 | + $this->fees[$element['label']] = array( |
|
112 | 112 | 'name' => $element['label'], |
113 | 113 | 'initial_fee' => $total, |
114 | 114 | 'recurring_fee' => 0, |
@@ -12,231 +12,231 @@ |
||
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 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Payment form submission taxes class |
@@ -35,17 +35,17 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @param GetPaid_Payment_Form_Submission $submission |
37 | 37 | */ |
38 | - public function __construct( $submission ) { |
|
38 | + public function __construct($submission) { |
|
39 | 39 | |
40 | 40 | // Validate VAT number. |
41 | - $this->validate_vat( $submission ); |
|
41 | + $this->validate_vat($submission); |
|
42 | 42 | |
43 | - foreach ( $submission->get_items() as $item ) { |
|
44 | - $this->process_item_tax( $item, $submission ); |
|
43 | + foreach ($submission->get_items() as $item) { |
|
44 | + $this->process_item_tax($item, $submission); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | // Process any existing invoice taxes. |
48 | - if ( $submission->has_invoice() ) { |
|
48 | + if ($submission->has_invoice()) { |
|
49 | 49 | $this->taxes = $submission->get_invoice()->get_taxes(); |
50 | 50 | } |
51 | 51 | |
@@ -65,19 +65,19 @@ discard block |
||
65 | 65 | * @param GetPaid_Form_Item $item |
66 | 66 | * @param GetPaid_Payment_Form_Submission $submission |
67 | 67 | */ |
68 | - public function process_item_tax( $item, $submission ) { |
|
68 | + public function process_item_tax($item, $submission) { |
|
69 | 69 | |
70 | - $rate = wpinv_get_tax_rate( $submission->country, $submission->state, $item->get_id() ); |
|
70 | + $rate = wpinv_get_tax_rate($submission->country, $submission->state, $item->get_id()); |
|
71 | 71 | $price = $item->get_sub_total(); |
72 | 72 | $item_tax = $price * $rate * 0.01; |
73 | 73 | |
74 | - if ( wpinv_prices_include_tax() ) { |
|
75 | - $item_tax = $price - ( $price - $price * $rate * 0.01 ); |
|
74 | + if (wpinv_prices_include_tax()) { |
|
75 | + $item_tax = $price - ($price - $price * $rate * 0.01); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | $this->initial_tax += $item_tax; |
79 | 79 | |
80 | - if ( $item->is_recurring() ) { |
|
80 | + if ($item->is_recurring()) { |
|
81 | 81 | $this->recurring_tax += $item_tax; |
82 | 82 | } |
83 | 83 | |
@@ -90,11 +90,11 @@ discard block |
||
90 | 90 | * @since 1.0.19 |
91 | 91 | * @return bool |
92 | 92 | */ |
93 | - public function has_digital_item( $submission ) { |
|
93 | + public function has_digital_item($submission) { |
|
94 | 94 | |
95 | - foreach ( $submission->get_items() as $item ) { |
|
95 | + foreach ($submission->get_items() as $item) { |
|
96 | 96 | |
97 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
97 | + if ('digital' == $item->get_vat_rule()) { |
|
98 | 98 | return true; |
99 | 99 | } |
100 | 100 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @return bool |
111 | 111 | */ |
112 | 112 | public function is_eu_store() { |
113 | - return $this->is_eu_country( wpinv_get_default_country() ); |
|
113 | + return $this->is_eu_country(wpinv_get_default_country()); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | * @since 1.0.19 |
121 | 121 | * @return bool |
122 | 122 | */ |
123 | - public function is_eu_country( $country ) { |
|
124 | - return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
123 | + public function is_eu_country($country) { |
|
124 | + return getpaid_is_eu_state($country) || getpaid_is_gst_country($country); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | * @since 1.0.19 |
132 | 132 | * @return bool |
133 | 133 | */ |
134 | - public function is_eu_transaction( $customer_country ) { |
|
135 | - return $this->is_eu_country( $customer_country ) && $this->is_eu_store(); |
|
134 | + public function is_eu_transaction($customer_country) { |
|
135 | + return $this->is_eu_country($customer_country) && $this->is_eu_store(); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -142,12 +142,12 @@ discard block |
||
142 | 142 | * @since 1.0.19 |
143 | 143 | * @return string |
144 | 144 | */ |
145 | - public function get_vat_number( $submission ) { |
|
145 | + public function get_vat_number($submission) { |
|
146 | 146 | |
147 | 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 ); |
|
148 | + $vat_number = $submission->get_field('wpinv_vat_number'); |
|
149 | + if (!empty($vat_number)) { |
|
150 | + return wpinv_clean($vat_number); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | // Retrieve from the invoice. |
@@ -161,12 +161,12 @@ discard block |
||
161 | 161 | * @since 1.0.19 |
162 | 162 | * @return string |
163 | 163 | */ |
164 | - public function get_company( $submission ) { |
|
164 | + public function get_company($submission) { |
|
165 | 165 | |
166 | 166 | // Retrieve from the posted data. |
167 | - $company = $submission->get_field( 'wpinv_company' ); |
|
168 | - if ( ! empty( $company ) ) { |
|
169 | - return wpinv_clean( $company ); |
|
167 | + $company = $submission->get_field('wpinv_company'); |
|
168 | + if (!empty($company)) { |
|
169 | + return wpinv_clean($company); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | // Retrieve from the invoice. |
@@ -181,10 +181,10 @@ discard block |
||
181 | 181 | * @since 1.0.19 |
182 | 182 | * @return string |
183 | 183 | */ |
184 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
184 | + public function requires_vat($ip_in_eu, $country_in_eu) { |
|
185 | 185 | |
186 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
187 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
186 | + $prevent_b2c = wpinv_get_option('vat_prevent_b2c_purchase'); |
|
187 | + $prevent_b2c = !empty($prevent_b2c); |
|
188 | 188 | $is_eu = $ip_in_eu || $country_in_eu; |
189 | 189 | |
190 | 190 | return $prevent_b2c && $is_eu; |
@@ -196,30 +196,30 @@ discard block |
||
196 | 196 | * @param GetPaid_Payment_Form_Submission $submission |
197 | 197 | * @since 1.0.19 |
198 | 198 | */ |
199 | - public function validate_vat( $submission ) { |
|
199 | + public function validate_vat($submission) { |
|
200 | 200 | |
201 | - $has_digital = $this->has_digital_item( $submission ); |
|
202 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
201 | + $has_digital = $this->has_digital_item($submission); |
|
202 | + $in_eu = $this->is_eu_transaction($submission->country); |
|
203 | 203 | |
204 | 204 | // Abort if we are not validating vat numbers. |
205 | - if ( ! $has_digital && ! $in_eu ) { |
|
205 | + if (!$has_digital && !$in_eu) { |
|
206 | 206 | return; |
207 | 207 | } |
208 | 208 | |
209 | 209 | // Prepare variables. |
210 | - $vat_number = $this->get_vat_number( $submission ); |
|
211 | - $company = $this->get_company( $submission ); |
|
210 | + $vat_number = $this->get_vat_number($submission); |
|
211 | + $company = $this->get_company($submission); |
|
212 | 212 | $ip_country = WPInv_EUVat::get_country_by_ip(); |
213 | - $is_eu = $this->is_eu_country( $submission->country ); |
|
214 | - $is_ip_eu = $this->is_eu_country( $ip_country ); |
|
213 | + $is_eu = $this->is_eu_country($submission->country); |
|
214 | + $is_ip_eu = $this->is_eu_country($ip_country); |
|
215 | 215 | |
216 | 216 | // If we're preventing business to consumer purchases, ensure |
217 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
217 | + if ($this->requires_vat($is_ip_eu, $is_eu) && empty($vat_number)) { |
|
218 | 218 | |
219 | 219 | // Ensure that a vat number has been specified. |
220 | 220 | throw new Exception( |
221 | 221 | wp_sprintf( |
222 | - __( 'Please enter your %s number to verify your purchase is by an EU business.', 'invoicing' ), |
|
222 | + __('Please enter your %s number to verify your purchase is by an EU business.', 'invoicing'), |
|
223 | 223 | getpaid_vat_name() |
224 | 224 | ) |
225 | 225 | ); |
@@ -227,14 +227,14 @@ discard block |
||
227 | 227 | } |
228 | 228 | |
229 | 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 ) ) { |
|
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 ); |
|
236 | + if (is_string($is_valid)) { |
|
237 | + throw new Exception($is_valid); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | } |
@@ -12,189 +12,189 @@ |
||
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 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Payment form submission discount class |
@@ -25,28 +25,28 @@ discard block |
||
25 | 25 | * @param float $initial_total |
26 | 26 | * @param float $recurring_total |
27 | 27 | */ |
28 | - public function __construct( $submission, $initial_total, $recurring_total ) { |
|
28 | + public function __construct($submission, $initial_total, $recurring_total) { |
|
29 | 29 | |
30 | 30 | // Process any existing invoice discounts. |
31 | - if ( $submission->has_invoice() ) { |
|
31 | + if ($submission->has_invoice()) { |
|
32 | 32 | $this->discounts = $submission->get_invoice()->get_discounts(); |
33 | 33 | } |
34 | 34 | |
35 | 35 | // Do we have a discount? |
36 | - $discount = $submission->get_field( 'discount' ); |
|
36 | + $discount = $submission->get_field('discount'); |
|
37 | 37 | |
38 | - if ( empty( $discount ) ) { |
|
38 | + if (empty($discount)) { |
|
39 | 39 | |
40 | - if ( isset( $this->discounts['discount_code'] ) ) { |
|
41 | - unset( $this->discounts['discount_code'] ); |
|
40 | + if (isset($this->discounts['discount_code'])) { |
|
41 | + unset($this->discounts['discount_code']); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | return; |
45 | 45 | } |
46 | 46 | |
47 | 47 | // Processes the discount code. |
48 | - $amount = max( $initial_total, $recurring_total ); |
|
49 | - $this->process_discount( $submission, $discount, $amount ); |
|
48 | + $amount = max($initial_total, $recurring_total); |
|
49 | + $this->process_discount($submission, $discount, $amount); |
|
50 | 50 | |
51 | 51 | } |
52 | 52 | |
@@ -57,29 +57,29 @@ discard block |
||
57 | 57 | * @param string $discount |
58 | 58 | * @param float $amount |
59 | 59 | */ |
60 | - public function process_discount( $submission, $discount, $amount ) { |
|
60 | + public function process_discount($submission, $discount, $amount) { |
|
61 | 61 | |
62 | 62 | // Fetch the discount. |
63 | - $discount = new WPInv_Discount( $discount ); |
|
63 | + $discount = new WPInv_Discount($discount); |
|
64 | 64 | |
65 | 65 | // Ensure it is active. |
66 | - if ( ! $this->is_discount_active( $discount ) ) { |
|
67 | - throw new Exception( __( 'Invalid or expired discount code', 'invoicing' ) ); |
|
66 | + if (!$this->is_discount_active($discount)) { |
|
67 | + throw new Exception(__('Invalid or expired discount code', 'invoicing')); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | // Exceeded limit. |
71 | - if ( $discount->has_exceeded_limit() ) { |
|
72 | - throw new Exception( __( 'This discount code has been used up', 'invoicing' ) ); |
|
71 | + if ($discount->has_exceeded_limit()) { |
|
72 | + throw new Exception(__('This discount code has been used up', 'invoicing')); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | // Validate usages. |
76 | - $this->validate_single_use_discount( $submission, $discount ); |
|
76 | + $this->validate_single_use_discount($submission, $discount); |
|
77 | 77 | |
78 | 78 | // Validate amount. |
79 | - $this->validate_discount_amount( $submission, $discount, $amount ); |
|
79 | + $this->validate_discount_amount($submission, $discount, $amount); |
|
80 | 80 | |
81 | 81 | // Save the discount. |
82 | - $this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount ); |
|
82 | + $this->discounts['discount_code'] = $this->calculate_discount($submission, $discount); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | * @param WPInv_Discount $discount |
89 | 89 | * @return bool |
90 | 90 | */ |
91 | - public function is_discount_active( $discount ) { |
|
92 | - return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired(); |
|
91 | + public function is_discount_active($discount) { |
|
92 | + return $discount->exists() && $discount->is_active() && $discount->has_started() && !$discount->is_expired(); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -98,13 +98,13 @@ discard block |
||
98 | 98 | * @param string $email |
99 | 99 | * @return int|string|false |
100 | 100 | */ |
101 | - public function get_user_id_or_email( $email ) { |
|
101 | + public function get_user_id_or_email($email) { |
|
102 | 102 | |
103 | - if ( is_user_logged_in() ) { |
|
103 | + if (is_user_logged_in()) { |
|
104 | 104 | return get_current_user_id(); |
105 | 105 | } |
106 | 106 | |
107 | - return empty( $email ) ? false : sanitize_email( $email ); |
|
107 | + return empty($email) ? false : sanitize_email($email); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -113,23 +113,23 @@ discard block |
||
113 | 113 | * @param GetPaid_Payment_Form_Submission $submission |
114 | 114 | * @param WPInv_Discount $discount |
115 | 115 | */ |
116 | - public function validate_single_use_discount( $submission, $discount ) { |
|
116 | + public function validate_single_use_discount($submission, $discount) { |
|
117 | 117 | |
118 | 118 | // Abort if it is not a single use discount. |
119 | - if ( ! $discount->is_single_use() ) { |
|
119 | + if (!$discount->is_single_use()) { |
|
120 | 120 | return; |
121 | 121 | } |
122 | 122 | |
123 | 123 | // Ensure there is a valid billing email. |
124 | - $user = $this->get_user_id_or_email( $submission->get_billing_email() ); |
|
124 | + $user = $this->get_user_id_or_email($submission->get_billing_email()); |
|
125 | 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' ) ); |
|
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 | 128 | } |
129 | 129 | |
130 | 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' ) ); |
|
131 | + if (!$discount->is_valid_for_user($user)) { |
|
132 | + throw new Exception(__('You have already used this discount', 'invoicing')); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | } |
@@ -141,18 +141,18 @@ discard block |
||
141 | 141 | * @param WPInv_Discount $discount |
142 | 142 | * @param float $amount |
143 | 143 | */ |
144 | - public function validate_discount_amount( $submission, $discount, $amount ) { |
|
144 | + public function validate_discount_amount($submission, $discount, $amount) { |
|
145 | 145 | |
146 | 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 ) ); |
|
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 | 150 | } |
151 | 151 | |
152 | 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 ) ); |
|
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 | 156 | } |
157 | 157 | |
158 | 158 | } |
@@ -166,24 +166,24 @@ discard block |
||
166 | 166 | * @param WPInv_Discount $discount |
167 | 167 | * @return array |
168 | 168 | */ |
169 | - public function calculate_discount( $submission, $discount ) { |
|
169 | + public function calculate_discount($submission, $discount) { |
|
170 | 170 | |
171 | 171 | $initial_discount = 0; |
172 | 172 | $recurring_discount = 0; |
173 | 173 | |
174 | - foreach ( $submission->get_items() as $item ) { |
|
174 | + foreach ($submission->get_items() as $item) { |
|
175 | 175 | |
176 | 176 | // Abort if it is not valid for this item. |
177 | - if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
177 | + if (!$discount->is_valid_for_items(array($item->get_id()))) { |
|
178 | 178 | continue; |
179 | 179 | } |
180 | 180 | |
181 | 181 | // Calculate the initial amount... |
182 | - $initial_discount += $discount->get_discounted_amount( $item->get_sub_total() ); |
|
182 | + $initial_discount += $discount->get_discounted_amount($item->get_sub_total()); |
|
183 | 183 | |
184 | 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() ); |
|
185 | + if ($item->is_recurring() && $discount->is_recurring()) { |
|
186 | + $recurring_discount += $discount->get_discounted_amount($item->get_recurring_sub_total()); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | } |
@@ -7,33 +7,33 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 | |
14 | 14 | <div class='form-group'> |
15 | 15 | <label class="d-block"> |
16 | - <span><?php esc_html_e( 'Alert Text', 'invoicing' ); ?></span> |
|
16 | + <span><?php esc_html_e('Alert Text', 'invoicing'); ?></span> |
|
17 | 17 | <textarea v-model='active_form_element.text' class='form-control' rows='3'></textarea> |
18 | 18 | </label> |
19 | 19 | </div> |
20 | 20 | |
21 | 21 | <div class='form-group form-check'> |
22 | 22 | <input :id="active_form_element.id + '_edit_dismissible'" v-model='active_form_element.dismissible' type='checkbox' class='form-check-input' /> |
23 | - <label class='form-check-label' :for="active_form_element.id + '_edit_dismissible'"><?php esc_html_e( 'Is Dismissible?', 'invoicing' ); ?></label> |
|
23 | + <label class='form-check-label' :for="active_form_element.id + '_edit_dismissible'"><?php esc_html_e('Is Dismissible?', 'invoicing'); ?></label> |
|
24 | 24 | </div> |
25 | 25 | |
26 | 26 | <div class='form-group'> |
27 | - <label :for="active_form_element.id + '_edit_type'"><?php esc_html_e( 'Alert Type', 'invoicing' ) ?></label> |
|
27 | + <label :for="active_form_element.id + '_edit_type'"><?php esc_html_e('Alert Type', 'invoicing') ?></label> |
|
28 | 28 | <select class='form-control custom-select' :id="active_form_element.id + '_edit_type'" v-model='active_form_element.class'> |
29 | - <option value='alert-primary'><?php esc_html_e( 'Primary', 'invoicing' ); ?></option> |
|
30 | - <option value='alert-secondary'><?php esc_html_e( 'Secondary', 'invoicing' ); ?></option> |
|
31 | - <option value='alert-success'><?php esc_html_e( 'Success', 'invoicing' ); ?></option> |
|
32 | - <option value='alert-danger'><?php esc_html_e( 'Danger', 'invoicing' ); ?></option> |
|
33 | - <option value='alert-warning'><?php esc_html_e( 'Warning', 'invoicing' ); ?></option> |
|
34 | - <option value='alert-info'><?php esc_html_e( 'Info', 'invoicing' ); ?></option> |
|
35 | - <option value='alert-light'><?php esc_html_e( 'Light', 'invoicing' ); ?></option> |
|
36 | - <option value='alert-dark'><?php esc_html_e( 'Dark', 'invoicing' ); ?></option> |
|
37 | - <option value='alert-link'><?php esc_html_e( 'Link', 'invoicing' ); ?></option> |
|
29 | + <option value='alert-primary'><?php esc_html_e('Primary', 'invoicing'); ?></option> |
|
30 | + <option value='alert-secondary'><?php esc_html_e('Secondary', 'invoicing'); ?></option> |
|
31 | + <option value='alert-success'><?php esc_html_e('Success', 'invoicing'); ?></option> |
|
32 | + <option value='alert-danger'><?php esc_html_e('Danger', 'invoicing'); ?></option> |
|
33 | + <option value='alert-warning'><?php esc_html_e('Warning', 'invoicing'); ?></option> |
|
34 | + <option value='alert-info'><?php esc_html_e('Info', 'invoicing'); ?></option> |
|
35 | + <option value='alert-light'><?php esc_html_e('Light', 'invoicing'); ?></option> |
|
36 | + <option value='alert-dark'><?php esc_html_e('Dark', 'invoicing'); ?></option> |
|
37 | + <option value='alert-link'><?php esc_html_e('Link', 'invoicing'); ?></option> |
|
38 | 38 | </select> |
39 | 39 | </div> |
@@ -7,30 +7,30 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | // Set the currency position. |
13 | 13 | $position = wpinv_currency_position(); |
14 | 14 | |
15 | -if ( $position == 'left_space' ) { |
|
15 | +if ($position == 'left_space') { |
|
16 | 16 | $position = 'left'; |
17 | 17 | } |
18 | 18 | |
19 | -if ( $position == 'right_space' ) { |
|
19 | +if ($position == 'right_space') { |
|
20 | 20 | $position = 'right'; |
21 | 21 | } |
22 | 22 | |
23 | 23 | echo aui()->input( |
24 | 24 | array( |
25 | - 'name' => esc_attr( $id ), |
|
26 | - 'id' => esc_attr( $id ) . uniqid( '_' ), |
|
27 | - 'placeholder' => empty( $placeholder ) ? wpinv_format_amount(0) : wpinv_format_amount( $placeholder ), |
|
28 | - 'value' => empty( $value ) ? wpinv_format_amount(0) : wpinv_format_amount( $value ), |
|
29 | - 'label' => empty( $label ) ? '' : wp_kses_post( $label ), |
|
25 | + 'name' => esc_attr($id), |
|
26 | + 'id' => esc_attr($id) . uniqid('_'), |
|
27 | + 'placeholder' => empty($placeholder) ? wpinv_format_amount(0) : wpinv_format_amount($placeholder), |
|
28 | + 'value' => empty($value) ? wpinv_format_amount(0) : wpinv_format_amount($value), |
|
29 | + 'label' => empty($label) ? '' : wp_kses_post($label), |
|
30 | 30 | 'label_type' => 'vertical', |
31 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
32 | - 'input_group_right' => $position == 'right' ? wpinv_currency_symbol( $form->get_currency() ) : '', |
|
33 | - 'input_group_left' => $position == 'left' ? wpinv_currency_symbol( $form->get_currency() ) : '', |
|
31 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
32 | + 'input_group_right' => $position == 'right' ? wpinv_currency_symbol($form->get_currency()) : '', |
|
33 | + 'input_group_left' => $position == 'left' ? wpinv_currency_symbol($form->get_currency()) : '', |
|
34 | 34 | 'class' => 'getpaid-refresh-on-change', |
35 | 35 | ) |
36 | 36 | ); |
@@ -13,616 +13,616 @@ discard block |
||
13 | 13 | class GetPaid_Post_Types_Admin { |
14 | 14 | |
15 | 15 | /** |
16 | - * Hook in methods. |
|
17 | - */ |
|
18 | - public static function init() { |
|
19 | - |
|
20 | - // Init metaboxes. |
|
21 | - GetPaid_Metaboxes::init(); |
|
22 | - |
|
23 | - // Filter the post updated messages. |
|
24 | - add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
25 | - |
|
26 | - // Filter post actions. |
|
27 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
28 | - |
|
29 | - // Invoice table columns. |
|
30 | - add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
31 | - add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
32 | - |
|
33 | - // Items table columns. |
|
34 | - add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
35 | - add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
36 | - add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
37 | - add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
38 | - add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
39 | - add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
40 | - |
|
41 | - // Payment forms columns. |
|
42 | - add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
43 | - add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
44 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
45 | - |
|
46 | - // Discount table columns. |
|
47 | - add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
48 | - |
|
49 | - // Deleting posts. |
|
50 | - add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
51 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Post updated messages. |
|
56 | - */ |
|
57 | - public static function post_updated_messages( $messages ) { |
|
58 | - global $post; |
|
59 | - |
|
60 | - $messages['wpi_discount'] = array( |
|
61 | - 0 => '', |
|
62 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
63 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
64 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
65 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
66 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
67 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
68 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
69 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
70 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
71 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
72 | - ); |
|
73 | - |
|
74 | - $messages['wpi_payment_form'] = array( |
|
75 | - 0 => '', |
|
76 | - 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
77 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
78 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
79 | - 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
80 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
81 | - 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
82 | - 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
83 | - 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
84 | - 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
85 | - 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
86 | - ); |
|
87 | - |
|
88 | - return $messages; |
|
89 | - |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Post row actions. |
|
94 | - */ |
|
95 | - public static function post_row_actions( $actions, $post ) { |
|
96 | - |
|
97 | - $post = get_post( $post ); |
|
98 | - |
|
99 | - // We do not want to edit the default payment form. |
|
100 | - if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) { |
|
101 | - unset( $actions['trash'] ); |
|
102 | - unset( $actions['inline hide-if-no-js'] ); |
|
103 | - } |
|
104 | - |
|
105 | - return $actions; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Returns an array of invoice table columns. |
|
110 | - */ |
|
111 | - public static function invoice_columns( $columns ) { |
|
112 | - |
|
113 | - $columns = array( |
|
114 | - 'cb' => $columns['cb'], |
|
115 | - 'number' => __( 'Invoice', 'invoicing' ), |
|
116 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
117 | - 'invoice_date' => __( 'Date', 'invoicing' ), |
|
118 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
119 | - 'recurring' => __( 'Recurring', 'invoicing' ), |
|
120 | - 'status' => __( 'Status', 'invoicing' ), |
|
121 | - 'wpi_actions' => __( 'Actions', 'invoicing' ), |
|
122 | - ); |
|
123 | - |
|
124 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Displays invoice table columns. |
|
129 | - */ |
|
130 | - public static function display_invoice_columns( $column_name, $post_id ) { |
|
131 | - |
|
132 | - $invoice = new WPInv_Invoice( $post_id ); |
|
133 | - |
|
134 | - switch ( $column_name ) { |
|
135 | - |
|
136 | - case 'invoice_date' : |
|
137 | - $date_time = esc_attr( $invoice->get_created_date() ); |
|
138 | - $date = getpaid_format_date_value( $date_time ); |
|
139 | - echo "<span title='$date_time'>$date</span>"; |
|
140 | - break; |
|
141 | - |
|
142 | - case 'amount' : |
|
143 | - |
|
144 | - $amount = $invoice->get_total(); |
|
145 | - $formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() ); |
|
146 | - |
|
147 | - if ( $invoice->is_refunded() ) { |
|
148 | - $refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() ); |
|
149 | - echo "<del>$formated_amount</del> <ins>$refunded_amount</ins>"; |
|
150 | - } else { |
|
151 | - |
|
152 | - $discount = $invoice->get_total_discount(); |
|
153 | - |
|
154 | - if ( ! empty( $discount ) ) { |
|
155 | - $new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() ); |
|
156 | - echo "<del>$new_amount</del> <ins>$formated_amount</ins>"; |
|
157 | - } else { |
|
158 | - echo $formated_amount; |
|
159 | - } |
|
160 | - |
|
161 | - } |
|
162 | - |
|
163 | - break; |
|
164 | - |
|
165 | - case 'status' : |
|
166 | - $status = sanitize_text_field( $invoice->get_status() ); |
|
167 | - $status_label = sanitize_text_field( $invoice->get_status_nicename() ); |
|
168 | - |
|
169 | - // If it is paid, show the gateway title. |
|
170 | - if ( $invoice->is_paid() ) { |
|
171 | - $gateway = sanitize_text_field( $invoice->get_gateway_title() ); |
|
172 | - $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
16 | + * Hook in methods. |
|
17 | + */ |
|
18 | + public static function init() { |
|
173 | 19 | |
174 | - echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
|
175 | - } else { |
|
176 | - echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>"; |
|
177 | - } |
|
20 | + // Init metaboxes. |
|
21 | + GetPaid_Metaboxes::init(); |
|
178 | 22 | |
179 | - // If it is not paid, display the overdue and view status. |
|
180 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
23 | + // Filter the post updated messages. |
|
24 | + add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
181 | 25 | |
182 | - // Invoice view status. |
|
183 | - if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
184 | - echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
185 | - } else { |
|
186 | - echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
187 | - } |
|
26 | + // Filter post actions. |
|
27 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
188 | 28 | |
189 | - // Display the overview status. |
|
190 | - if ( wpinv_get_option( 'overdue_active' ) ) { |
|
191 | - $due_date = $invoice->get_due_date(); |
|
192 | - $fomatted = getpaid_format_date( $due_date ); |
|
29 | + // Invoice table columns. |
|
30 | + add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
31 | + add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
193 | 32 | |
194 | - if ( ! empty( $fomatted ) ) { |
|
195 | - $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted ); |
|
196 | - echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"; |
|
197 | - } |
|
198 | - } |
|
33 | + // Items table columns. |
|
34 | + add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
35 | + add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
36 | + add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
37 | + add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
38 | + add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
39 | + add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
199 | 40 | |
200 | - } |
|
41 | + // Payment forms columns. |
|
42 | + add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
43 | + add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
44 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
201 | 45 | |
202 | - break; |
|
46 | + // Discount table columns. |
|
47 | + add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
203 | 48 | |
204 | - case 'recurring': |
|
49 | + // Deleting posts. |
|
50 | + add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
51 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
52 | + } |
|
205 | 53 | |
206 | - if ( $invoice->is_recurring() ) { |
|
207 | - echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
208 | - } else { |
|
209 | - echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
210 | - } |
|
211 | - break; |
|
54 | + /** |
|
55 | + * Post updated messages. |
|
56 | + */ |
|
57 | + public static function post_updated_messages( $messages ) { |
|
58 | + global $post; |
|
59 | + |
|
60 | + $messages['wpi_discount'] = array( |
|
61 | + 0 => '', |
|
62 | + 1 => __( 'Discount updated.', 'invoicing' ), |
|
63 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
64 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
65 | + 4 => __( 'Discount updated.', 'invoicing' ), |
|
66 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
67 | + 6 => __( 'Discount updated.', 'invoicing' ), |
|
68 | + 7 => __( 'Discount saved.', 'invoicing' ), |
|
69 | + 8 => __( 'Discount submitted.', 'invoicing' ), |
|
70 | + 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
71 | + 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
72 | + ); |
|
73 | + |
|
74 | + $messages['wpi_payment_form'] = array( |
|
75 | + 0 => '', |
|
76 | + 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
77 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
78 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
79 | + 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
80 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
81 | + 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
82 | + 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
83 | + 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
84 | + 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
85 | + 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
86 | + ); |
|
87 | + |
|
88 | + return $messages; |
|
89 | + |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Post row actions. |
|
94 | + */ |
|
95 | + public static function post_row_actions( $actions, $post ) { |
|
96 | + |
|
97 | + $post = get_post( $post ); |
|
98 | + |
|
99 | + // We do not want to edit the default payment form. |
|
100 | + if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) { |
|
101 | + unset( $actions['trash'] ); |
|
102 | + unset( $actions['inline hide-if-no-js'] ); |
|
103 | + } |
|
104 | + |
|
105 | + return $actions; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Returns an array of invoice table columns. |
|
110 | + */ |
|
111 | + public static function invoice_columns( $columns ) { |
|
112 | + |
|
113 | + $columns = array( |
|
114 | + 'cb' => $columns['cb'], |
|
115 | + 'number' => __( 'Invoice', 'invoicing' ), |
|
116 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
117 | + 'invoice_date' => __( 'Date', 'invoicing' ), |
|
118 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
119 | + 'recurring' => __( 'Recurring', 'invoicing' ), |
|
120 | + 'status' => __( 'Status', 'invoicing' ), |
|
121 | + 'wpi_actions' => __( 'Actions', 'invoicing' ), |
|
122 | + ); |
|
123 | + |
|
124 | + return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Displays invoice table columns. |
|
129 | + */ |
|
130 | + public static function display_invoice_columns( $column_name, $post_id ) { |
|
131 | + |
|
132 | + $invoice = new WPInv_Invoice( $post_id ); |
|
133 | + |
|
134 | + switch ( $column_name ) { |
|
135 | + |
|
136 | + case 'invoice_date' : |
|
137 | + $date_time = esc_attr( $invoice->get_created_date() ); |
|
138 | + $date = getpaid_format_date_value( $date_time ); |
|
139 | + echo "<span title='$date_time'>$date</span>"; |
|
140 | + break; |
|
141 | + |
|
142 | + case 'amount' : |
|
143 | + |
|
144 | + $amount = $invoice->get_total(); |
|
145 | + $formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() ); |
|
146 | + |
|
147 | + if ( $invoice->is_refunded() ) { |
|
148 | + $refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() ); |
|
149 | + echo "<del>$formated_amount</del> <ins>$refunded_amount</ins>"; |
|
150 | + } else { |
|
151 | + |
|
152 | + $discount = $invoice->get_total_discount(); |
|
153 | + |
|
154 | + if ( ! empty( $discount ) ) { |
|
155 | + $new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() ); |
|
156 | + echo "<del>$new_amount</del> <ins>$formated_amount</ins>"; |
|
157 | + } else { |
|
158 | + echo $formated_amount; |
|
159 | + } |
|
160 | + |
|
161 | + } |
|
162 | + |
|
163 | + break; |
|
164 | + |
|
165 | + case 'status' : |
|
166 | + $status = sanitize_text_field( $invoice->get_status() ); |
|
167 | + $status_label = sanitize_text_field( $invoice->get_status_nicename() ); |
|
168 | + |
|
169 | + // If it is paid, show the gateway title. |
|
170 | + if ( $invoice->is_paid() ) { |
|
171 | + $gateway = sanitize_text_field( $invoice->get_gateway_title() ); |
|
172 | + $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
212 | 173 | |
213 | - case 'number' : |
|
174 | + echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
|
175 | + } else { |
|
176 | + echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>"; |
|
177 | + } |
|
214 | 178 | |
215 | - $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
216 | - $invoice_number = sanitize_text_field( $invoice->get_number() ); |
|
217 | - $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
179 | + // If it is not paid, display the overdue and view status. |
|
180 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
218 | 181 | |
219 | - echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
|
182 | + // Invoice view status. |
|
183 | + if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
184 | + echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
185 | + } else { |
|
186 | + echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
187 | + } |
|
220 | 188 | |
221 | - break; |
|
189 | + // Display the overview status. |
|
190 | + if ( wpinv_get_option( 'overdue_active' ) ) { |
|
191 | + $due_date = $invoice->get_due_date(); |
|
192 | + $fomatted = getpaid_format_date( $due_date ); |
|
222 | 193 | |
223 | - case 'customer' : |
|
194 | + if ( ! empty( $fomatted ) ) { |
|
195 | + $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted ); |
|
196 | + echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"; |
|
197 | + } |
|
198 | + } |
|
199 | + |
|
200 | + } |
|
201 | + |
|
202 | + break; |
|
203 | + |
|
204 | + case 'recurring': |
|
205 | + |
|
206 | + if ( $invoice->is_recurring() ) { |
|
207 | + echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
208 | + } else { |
|
209 | + echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
210 | + } |
|
211 | + break; |
|
212 | + |
|
213 | + case 'number' : |
|
214 | + |
|
215 | + $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
216 | + $invoice_number = sanitize_text_field( $invoice->get_number() ); |
|
217 | + $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
218 | + |
|
219 | + echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
|
220 | + |
|
221 | + break; |
|
222 | + |
|
223 | + case 'customer' : |
|
224 | 224 | |
225 | - $customer_name = $invoice->get_user_full_name(); |
|
225 | + $customer_name = $invoice->get_user_full_name(); |
|
226 | 226 | |
227 | - if ( empty( $customer_name ) ) { |
|
228 | - $customer_name = $invoice->get_email(); |
|
229 | - } |
|
227 | + if ( empty( $customer_name ) ) { |
|
228 | + $customer_name = $invoice->get_email(); |
|
229 | + } |
|
230 | 230 | |
231 | - if ( ! empty( $customer_name ) ) { |
|
232 | - $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
233 | - $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
234 | - echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
|
235 | - } else { |
|
236 | - echo '<div>—</div>'; |
|
237 | - } |
|
231 | + if ( ! empty( $customer_name ) ) { |
|
232 | + $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
233 | + $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
234 | + echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
|
235 | + } else { |
|
236 | + echo '<div>—</div>'; |
|
237 | + } |
|
238 | + |
|
239 | + break; |
|
240 | + |
|
241 | + case 'wpi_actions' : |
|
242 | + |
|
243 | + if ( $invoice->is_draft() ) { |
|
244 | + return; |
|
245 | + } |
|
246 | + |
|
247 | + $url = esc_url( $invoice->get_view_url() ); |
|
248 | + $print = esc_attr__( 'Print invoice', 'invoicing' ); |
|
249 | + echo " <a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>"; |
|
250 | + |
|
251 | + $url = esc_url( |
|
252 | + wp_nonce_url( |
|
253 | + add_query_arg( |
|
254 | + array( |
|
255 | + 'getpaid-admin-action' => 'send_invoice', |
|
256 | + 'invoice_id' => $invoice->get_id() |
|
257 | + ) |
|
258 | + ), |
|
259 | + 'getpaid-nonce', |
|
260 | + 'getpaid-nonce' |
|
261 | + ) |
|
262 | + ); |
|
263 | + |
|
264 | + $send = esc_attr__( 'Send invoice to customer', 'invoicing' ); |
|
265 | + echo " <a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>"; |
|
266 | + |
|
267 | + break; |
|
268 | + } |
|
238 | 269 | |
239 | - break; |
|
270 | + } |
|
240 | 271 | |
241 | - case 'wpi_actions' : |
|
242 | - |
|
243 | - if ( $invoice->is_draft() ) { |
|
244 | - return; |
|
245 | - } |
|
246 | - |
|
247 | - $url = esc_url( $invoice->get_view_url() ); |
|
248 | - $print = esc_attr__( 'Print invoice', 'invoicing' ); |
|
249 | - echo " <a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>"; |
|
272 | + /** |
|
273 | + * Returns an array of payment forms table columns. |
|
274 | + */ |
|
275 | + public static function payment_form_columns( $columns ) { |
|
250 | 276 | |
251 | - $url = esc_url( |
|
252 | - wp_nonce_url( |
|
253 | - add_query_arg( |
|
254 | - array( |
|
255 | - 'getpaid-admin-action' => 'send_invoice', |
|
256 | - 'invoice_id' => $invoice->get_id() |
|
257 | - ) |
|
258 | - ), |
|
259 | - 'getpaid-nonce', |
|
260 | - 'getpaid-nonce' |
|
261 | - ) |
|
262 | - ); |
|
277 | + $columns = array( |
|
278 | + 'cb' => $columns['cb'], |
|
279 | + 'title' => __( 'Name', 'invoicing' ), |
|
280 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
281 | + 'earnings' => __( 'Revenue', 'invoicing' ), |
|
282 | + 'refunds' => __( 'Refunded', 'invoicing' ), |
|
283 | + 'items' => __( 'Items', 'invoicing' ), |
|
284 | + 'date' => __( 'Date', 'invoicing' ), |
|
285 | + ); |
|
263 | 286 | |
264 | - $send = esc_attr__( 'Send invoice to customer', 'invoicing' ); |
|
265 | - echo " <a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>"; |
|
287 | + return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
266 | 288 | |
267 | - break; |
|
268 | - } |
|
289 | + } |
|
269 | 290 | |
270 | - } |
|
291 | + /** |
|
292 | + * Displays payment form table columns. |
|
293 | + */ |
|
294 | + public static function display_payment_form_columns( $column_name, $post_id ) { |
|
271 | 295 | |
272 | - /** |
|
273 | - * Returns an array of payment forms table columns. |
|
274 | - */ |
|
275 | - public static function payment_form_columns( $columns ) { |
|
296 | + // Retrieve the payment form. |
|
297 | + $form = new GetPaid_Payment_Form( $post_id ); |
|
276 | 298 | |
277 | - $columns = array( |
|
278 | - 'cb' => $columns['cb'], |
|
279 | - 'title' => __( 'Name', 'invoicing' ), |
|
280 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
281 | - 'earnings' => __( 'Revenue', 'invoicing' ), |
|
282 | - 'refunds' => __( 'Refunded', 'invoicing' ), |
|
283 | - 'items' => __( 'Items', 'invoicing' ), |
|
284 | - 'date' => __( 'Date', 'invoicing' ), |
|
285 | - ); |
|
299 | + switch ( $column_name ) { |
|
286 | 300 | |
287 | - return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
301 | + case 'earnings' : |
|
302 | + echo wpinv_price( wpinv_format_amount( $form->get_earned() ) ); |
|
303 | + break; |
|
288 | 304 | |
289 | - } |
|
305 | + case 'refunds' : |
|
306 | + echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
307 | + break; |
|
290 | 308 | |
291 | - /** |
|
292 | - * Displays payment form table columns. |
|
293 | - */ |
|
294 | - public static function display_payment_form_columns( $column_name, $post_id ) { |
|
309 | + case 'refunds' : |
|
310 | + echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
311 | + break; |
|
295 | 312 | |
296 | - // Retrieve the payment form. |
|
297 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
313 | + case 'shortcode' : |
|
298 | 314 | |
299 | - switch ( $column_name ) { |
|
315 | + if ( $form->is_default() ) { |
|
316 | + echo '—'; |
|
317 | + } else { |
|
318 | + echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
319 | + } |
|
300 | 320 | |
301 | - case 'earnings' : |
|
302 | - echo wpinv_price( wpinv_format_amount( $form->get_earned() ) ); |
|
303 | - break; |
|
321 | + break; |
|
304 | 322 | |
305 | - case 'refunds' : |
|
306 | - echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
307 | - break; |
|
323 | + case 'items' : |
|
308 | 324 | |
309 | - case 'refunds' : |
|
310 | - echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
311 | - break; |
|
325 | + $items = $form->get_items(); |
|
312 | 326 | |
313 | - case 'shortcode' : |
|
327 | + if ( $form->is_default() || empty( $items ) ) { |
|
328 | + echo '—'; |
|
329 | + return; |
|
330 | + } |
|
314 | 331 | |
315 | - if ( $form->is_default() ) { |
|
316 | - echo '—'; |
|
317 | - } else { |
|
318 | - echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
319 | - } |
|
332 | + $_items = array(); |
|
320 | 333 | |
321 | - break; |
|
334 | + foreach ( $items as $item ) { |
|
335 | + $url = $item->get_edit_url(); |
|
322 | 336 | |
323 | - case 'items' : |
|
337 | + if ( empty( $url ) ) { |
|
338 | + $_items[] = sanitize_text_field( $item->get_name() ); |
|
339 | + } else { |
|
340 | + $_items[] = sprintf( |
|
341 | + '<a href="%s">%s</a>', |
|
342 | + esc_url( $url ), |
|
343 | + sanitize_text_field( $item->get_name() ) |
|
344 | + ); |
|
345 | + } |
|
324 | 346 | |
325 | - $items = $form->get_items(); |
|
347 | + } |
|
326 | 348 | |
327 | - if ( $form->is_default() || empty( $items ) ) { |
|
328 | - echo '—'; |
|
329 | - return; |
|
330 | - } |
|
349 | + echo implode( '<br>', $_items ); |
|
331 | 350 | |
332 | - $_items = array(); |
|
351 | + break; |
|
333 | 352 | |
334 | - foreach ( $items as $item ) { |
|
335 | - $url = $item->get_edit_url(); |
|
353 | + } |
|
336 | 354 | |
337 | - if ( empty( $url ) ) { |
|
338 | - $_items[] = sanitize_text_field( $item->get_name() ); |
|
339 | - } else { |
|
340 | - $_items[] = sprintf( |
|
341 | - '<a href="%s">%s</a>', |
|
342 | - esc_url( $url ), |
|
343 | - sanitize_text_field( $item->get_name() ) |
|
344 | - ); |
|
345 | - } |
|
355 | + } |
|
346 | 356 | |
347 | - } |
|
357 | + /** |
|
358 | + * Filters post states. |
|
359 | + */ |
|
360 | + public static function filter_payment_form_state( $post_states, $post ) { |
|
348 | 361 | |
349 | - echo implode( '<br>', $_items ); |
|
362 | + if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
363 | + $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
364 | + } |
|
365 | + |
|
366 | + return $post_states; |
|
350 | 367 | |
351 | - break; |
|
368 | + } |
|
352 | 369 | |
353 | - } |
|
370 | + /** |
|
371 | + * Returns an array of coupon table columns. |
|
372 | + */ |
|
373 | + public static function discount_columns( $columns ) { |
|
374 | + |
|
375 | + $columns = array( |
|
376 | + 'cb' => $columns['cb'], |
|
377 | + 'title' => __( 'Name', 'invoicing' ), |
|
378 | + 'code' => __( 'Code', 'invoicing' ), |
|
379 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
380 | + 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
381 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
382 | + 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
383 | + ); |
|
384 | + |
|
385 | + return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
386 | + } |
|
354 | 387 | |
355 | - } |
|
388 | + /** |
|
389 | + * Filters post states. |
|
390 | + */ |
|
391 | + public static function filter_discount_state( $post_states, $post ) { |
|
356 | 392 | |
357 | - /** |
|
358 | - * Filters post states. |
|
359 | - */ |
|
360 | - public static function filter_payment_form_state( $post_states, $post ) { |
|
393 | + if ( 'wpi_discount' == $post->post_type ) { |
|
361 | 394 | |
362 | - if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
363 | - $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
364 | - } |
|
365 | - |
|
366 | - return $post_states; |
|
395 | + $discount = new WPInv_Discount( $post ); |
|
367 | 396 | |
368 | - } |
|
397 | + $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
369 | 398 | |
370 | - /** |
|
371 | - * Returns an array of coupon table columns. |
|
372 | - */ |
|
373 | - public static function discount_columns( $columns ) { |
|
399 | + if ( $status != 'publish' ) { |
|
400 | + return array( |
|
401 | + 'discount_status' => wpinv_discount_status( $status ), |
|
402 | + ); |
|
403 | + } |
|
374 | 404 | |
375 | - $columns = array( |
|
376 | - 'cb' => $columns['cb'], |
|
377 | - 'title' => __( 'Name', 'invoicing' ), |
|
378 | - 'code' => __( 'Code', 'invoicing' ), |
|
379 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
380 | - 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
381 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
382 | - 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
383 | - ); |
|
405 | + return array(); |
|
384 | 406 | |
385 | - return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
386 | - } |
|
407 | + } |
|
387 | 408 | |
388 | - /** |
|
389 | - * Filters post states. |
|
390 | - */ |
|
391 | - public static function filter_discount_state( $post_states, $post ) { |
|
409 | + return $post_states; |
|
392 | 410 | |
393 | - if ( 'wpi_discount' == $post->post_type ) { |
|
411 | + } |
|
394 | 412 | |
395 | - $discount = new WPInv_Discount( $post ); |
|
413 | + /** |
|
414 | + * Returns an array of items table columns. |
|
415 | + */ |
|
416 | + public static function item_columns( $columns ) { |
|
417 | + global $wpinv_euvat; |
|
418 | + |
|
419 | + $columns = array( |
|
420 | + 'cb' => $columns['cb'], |
|
421 | + 'title' => __( 'Name', 'invoicing' ), |
|
422 | + 'price' => __( 'Price', 'invoicing' ), |
|
423 | + 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
424 | + 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
425 | + 'type' => __( 'Type', 'invoicing' ), |
|
426 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
427 | + ); |
|
428 | + |
|
429 | + if ( ! $wpinv_euvat->allow_vat_rules() ) { |
|
430 | + unset( $columns['vat_rule'] ); |
|
431 | + } |
|
396 | 432 | |
397 | - $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
433 | + if ( ! $wpinv_euvat->allow_vat_classes() ) { |
|
434 | + unset( $columns['vat_class'] ); |
|
435 | + } |
|
398 | 436 | |
399 | - if ( $status != 'publish' ) { |
|
400 | - return array( |
|
401 | - 'discount_status' => wpinv_discount_status( $status ), |
|
402 | - ); |
|
403 | - } |
|
437 | + return apply_filters( 'wpi_item_table_columns', $columns ); |
|
438 | + } |
|
404 | 439 | |
405 | - return array(); |
|
440 | + /** |
|
441 | + * Returns an array of sortable items table columns. |
|
442 | + */ |
|
443 | + public static function sortable_item_columns( $columns ) { |
|
444 | + |
|
445 | + return array_merge( |
|
446 | + $columns, |
|
447 | + array( |
|
448 | + 'price' => 'price', |
|
449 | + 'vat_rule' => 'vat_rule', |
|
450 | + 'vat_class' => 'vat_class', |
|
451 | + 'type' => 'type', |
|
452 | + ) |
|
453 | + ); |
|
454 | + |
|
455 | + } |
|
406 | 456 | |
407 | - } |
|
457 | + /** |
|
458 | + * Displays items table columns. |
|
459 | + */ |
|
460 | + public static function display_item_columns( $column_name, $post_id ) { |
|
461 | + global $wpinv_euvat; |
|
408 | 462 | |
409 | - return $post_states; |
|
463 | + $item = new WPInv_Item( $post_id ); |
|
410 | 464 | |
411 | - } |
|
465 | + switch ( $column_name ) { |
|
412 | 466 | |
413 | - /** |
|
414 | - * Returns an array of items table columns. |
|
415 | - */ |
|
416 | - public static function item_columns( $columns ) { |
|
417 | - global $wpinv_euvat; |
|
467 | + case 'price' : |
|
418 | 468 | |
419 | - $columns = array( |
|
420 | - 'cb' => $columns['cb'], |
|
421 | - 'title' => __( 'Name', 'invoicing' ), |
|
422 | - 'price' => __( 'Price', 'invoicing' ), |
|
423 | - 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
424 | - 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
425 | - 'type' => __( 'Type', 'invoicing' ), |
|
426 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
427 | - ); |
|
469 | + if ( ! $item->is_recurring() ) { |
|
470 | + echo $item->get_the_price(); |
|
471 | + break; |
|
472 | + } |
|
428 | 473 | |
429 | - if ( ! $wpinv_euvat->allow_vat_rules() ) { |
|
430 | - unset( $columns['vat_rule'] ); |
|
431 | - } |
|
474 | + $price = wp_sprintf( |
|
475 | + __( '%s / %s', 'invoicing' ), |
|
476 | + $item->get_the_price(), |
|
477 | + getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
478 | + ); |
|
432 | 479 | |
433 | - if ( ! $wpinv_euvat->allow_vat_classes() ) { |
|
434 | - unset( $columns['vat_class'] ); |
|
435 | - } |
|
480 | + if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
481 | + echo $price; |
|
482 | + break; |
|
483 | + } |
|
436 | 484 | |
437 | - return apply_filters( 'wpi_item_table_columns', $columns ); |
|
438 | - } |
|
485 | + echo $item->get_the_initial_price(); |
|
439 | 486 | |
440 | - /** |
|
441 | - * Returns an array of sortable items table columns. |
|
442 | - */ |
|
443 | - public static function sortable_item_columns( $columns ) { |
|
487 | + echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
488 | + break; |
|
444 | 489 | |
445 | - return array_merge( |
|
446 | - $columns, |
|
447 | - array( |
|
448 | - 'price' => 'price', |
|
449 | - 'vat_rule' => 'vat_rule', |
|
450 | - 'vat_class' => 'vat_class', |
|
451 | - 'type' => 'type', |
|
452 | - ) |
|
453 | - ); |
|
490 | + case 'vat_rule' : |
|
491 | + echo $wpinv_euvat->item_rule_label( $item->get_id() ); |
|
492 | + break; |
|
454 | 493 | |
455 | - } |
|
494 | + case 'vat_class' : |
|
495 | + echo $wpinv_euvat->item_class_label( $item->get_id() ); |
|
496 | + break; |
|
456 | 497 | |
457 | - /** |
|
458 | - * Displays items table columns. |
|
459 | - */ |
|
460 | - public static function display_item_columns( $column_name, $post_id ) { |
|
461 | - global $wpinv_euvat; |
|
498 | + case 'shortcode' : |
|
499 | + echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
500 | + break; |
|
462 | 501 | |
463 | - $item = new WPInv_Item( $post_id ); |
|
502 | + case 'type' : |
|
503 | + echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
504 | + break; |
|
464 | 505 | |
465 | - switch ( $column_name ) { |
|
506 | + } |
|
466 | 507 | |
467 | - case 'price' : |
|
508 | + } |
|
468 | 509 | |
469 | - if ( ! $item->is_recurring() ) { |
|
470 | - echo $item->get_the_price(); |
|
471 | - break; |
|
472 | - } |
|
510 | + /** |
|
511 | + * Lets users filter items using taxes. |
|
512 | + */ |
|
513 | + public static function add_item_filters( $post_type ) { |
|
514 | + $wpinv_euvat = getpaid_tax(); |
|
515 | + |
|
516 | + // Abort if we're not dealing with items. |
|
517 | + if ( $post_type != 'wpi_item' ) { |
|
518 | + return; |
|
519 | + } |
|
520 | + |
|
521 | + // Filter by vat rules. |
|
522 | + if ( $wpinv_euvat->allow_vat_rules() ) { |
|
523 | + |
|
524 | + // Sanitize selected vat rule. |
|
525 | + $vat_rule = ''; |
|
526 | + $vat_rules = $wpinv_euvat->get_rules(); |
|
527 | + if ( isset( $_GET['vat_rule'] ) ) { |
|
528 | + $vat_rule = $_GET['vat_rule']; |
|
529 | + } |
|
530 | + |
|
531 | + // Filter by VAT rule. |
|
532 | + echo wpinv_html_select( |
|
533 | + array( |
|
534 | + 'options' => array_merge( |
|
535 | + array( |
|
536 | + '' => __( 'All VAT rules', 'invoicing' ) |
|
537 | + ), |
|
538 | + $vat_rules |
|
539 | + ), |
|
540 | + 'name' => 'vat_rule', |
|
541 | + 'id' => 'vat_rule', |
|
542 | + 'selected' => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '', |
|
543 | + 'show_option_all' => false, |
|
544 | + 'show_option_none' => false, |
|
545 | + 'class' => 'gdmbx2-text-medium', |
|
546 | + ) |
|
547 | + ); |
|
548 | + |
|
549 | + // Filter by VAT class. |
|
550 | + } |
|
473 | 551 | |
474 | - $price = wp_sprintf( |
|
475 | - __( '%s / %s', 'invoicing' ), |
|
476 | - $item->get_the_price(), |
|
477 | - getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
478 | - ); |
|
552 | + // Filter by vat class. |
|
553 | + if ( $wpinv_euvat->allow_vat_classes() ) { |
|
554 | + |
|
555 | + // Sanitize selected vat rule. |
|
556 | + $vat_class = ''; |
|
557 | + $vat_classes = $wpinv_euvat->get_all_classes(); |
|
558 | + if ( isset( $_GET['vat_class'] ) ) { |
|
559 | + $vat_class = $_GET['vat_class']; |
|
560 | + } |
|
561 | + |
|
562 | + echo wpinv_html_select( |
|
563 | + array( |
|
564 | + 'options' => array_merge( |
|
565 | + array( |
|
566 | + '' => __( 'All VAT classes', 'invoicing' ) |
|
567 | + ), |
|
568 | + $vat_classes |
|
569 | + ), |
|
570 | + 'name' => 'vat_class', |
|
571 | + 'id' => 'vat_class', |
|
572 | + 'selected' => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '', |
|
573 | + 'show_option_all' => false, |
|
574 | + 'show_option_none' => false, |
|
575 | + 'class' => 'gdmbx2-text-medium', |
|
576 | + ) |
|
577 | + ); |
|
479 | 578 | |
480 | - if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
481 | - echo $price; |
|
482 | - break; |
|
483 | - } |
|
579 | + } |
|
484 | 580 | |
485 | - echo $item->get_the_initial_price(); |
|
581 | + // Filter by item type. |
|
582 | + $type = ''; |
|
583 | + if ( isset( $_GET['type'] ) ) { |
|
584 | + $type = $_GET['type']; |
|
585 | + } |
|
486 | 586 | |
487 | - echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
488 | - break; |
|
587 | + echo wpinv_html_select( |
|
588 | + array( |
|
589 | + 'options' => array_merge( |
|
590 | + array( |
|
591 | + '' => __( 'All item types', 'invoicing' ) |
|
592 | + ), |
|
593 | + wpinv_get_item_types() |
|
594 | + ), |
|
595 | + 'name' => 'type', |
|
596 | + 'id' => 'type', |
|
597 | + 'selected' => in_array( $type, wpinv_item_types() ) ? $type : '', |
|
598 | + 'show_option_all' => false, |
|
599 | + 'show_option_none' => false, |
|
600 | + 'class' => 'gdmbx2-text-medium', |
|
601 | + ) |
|
602 | + ); |
|
603 | + |
|
604 | + } |
|
489 | 605 | |
490 | - case 'vat_rule' : |
|
491 | - echo $wpinv_euvat->item_rule_label( $item->get_id() ); |
|
492 | - break; |
|
606 | + /** |
|
607 | + * Filters the item query. |
|
608 | + */ |
|
609 | + public static function filter_item_query( $query ) { |
|
493 | 610 | |
494 | - case 'vat_class' : |
|
495 | - echo $wpinv_euvat->item_class_label( $item->get_id() ); |
|
496 | - break; |
|
611 | + // modify the query only if it admin and main query. |
|
612 | + if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
613 | + return $query; |
|
614 | + } |
|
497 | 615 | |
498 | - case 'shortcode' : |
|
499 | - echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
500 | - break; |
|
616 | + // we want to modify the query for our items. |
|
617 | + if ( 'wpi_item' != $query->query['post_type'] ){ |
|
618 | + return $query; |
|
619 | + } |
|
501 | 620 | |
502 | - case 'type' : |
|
503 | - echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
504 | - break; |
|
621 | + if ( empty( $query->query_vars['meta_query'] ) ) { |
|
622 | + $query->query_vars['meta_query'] = array(); |
|
623 | + } |
|
505 | 624 | |
506 | - } |
|
507 | - |
|
508 | - } |
|
509 | - |
|
510 | - /** |
|
511 | - * Lets users filter items using taxes. |
|
512 | - */ |
|
513 | - public static function add_item_filters( $post_type ) { |
|
514 | - $wpinv_euvat = getpaid_tax(); |
|
515 | - |
|
516 | - // Abort if we're not dealing with items. |
|
517 | - if ( $post_type != 'wpi_item' ) { |
|
518 | - return; |
|
519 | - } |
|
520 | - |
|
521 | - // Filter by vat rules. |
|
522 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
523 | - |
|
524 | - // Sanitize selected vat rule. |
|
525 | - $vat_rule = ''; |
|
526 | - $vat_rules = $wpinv_euvat->get_rules(); |
|
527 | - if ( isset( $_GET['vat_rule'] ) ) { |
|
528 | - $vat_rule = $_GET['vat_rule']; |
|
529 | - } |
|
530 | - |
|
531 | - // Filter by VAT rule. |
|
532 | - echo wpinv_html_select( |
|
533 | - array( |
|
534 | - 'options' => array_merge( |
|
535 | - array( |
|
536 | - '' => __( 'All VAT rules', 'invoicing' ) |
|
537 | - ), |
|
538 | - $vat_rules |
|
539 | - ), |
|
540 | - 'name' => 'vat_rule', |
|
541 | - 'id' => 'vat_rule', |
|
542 | - 'selected' => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '', |
|
543 | - 'show_option_all' => false, |
|
544 | - 'show_option_none' => false, |
|
545 | - 'class' => 'gdmbx2-text-medium', |
|
546 | - ) |
|
547 | - ); |
|
548 | - |
|
549 | - // Filter by VAT class. |
|
550 | - } |
|
551 | - |
|
552 | - // Filter by vat class. |
|
553 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
554 | - |
|
555 | - // Sanitize selected vat rule. |
|
556 | - $vat_class = ''; |
|
557 | - $vat_classes = $wpinv_euvat->get_all_classes(); |
|
558 | - if ( isset( $_GET['vat_class'] ) ) { |
|
559 | - $vat_class = $_GET['vat_class']; |
|
560 | - } |
|
561 | - |
|
562 | - echo wpinv_html_select( |
|
563 | - array( |
|
564 | - 'options' => array_merge( |
|
565 | - array( |
|
566 | - '' => __( 'All VAT classes', 'invoicing' ) |
|
567 | - ), |
|
568 | - $vat_classes |
|
569 | - ), |
|
570 | - 'name' => 'vat_class', |
|
571 | - 'id' => 'vat_class', |
|
572 | - 'selected' => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '', |
|
573 | - 'show_option_all' => false, |
|
574 | - 'show_option_none' => false, |
|
575 | - 'class' => 'gdmbx2-text-medium', |
|
576 | - ) |
|
577 | - ); |
|
578 | - |
|
579 | - } |
|
580 | - |
|
581 | - // Filter by item type. |
|
582 | - $type = ''; |
|
583 | - if ( isset( $_GET['type'] ) ) { |
|
584 | - $type = $_GET['type']; |
|
585 | - } |
|
586 | - |
|
587 | - echo wpinv_html_select( |
|
588 | - array( |
|
589 | - 'options' => array_merge( |
|
590 | - array( |
|
591 | - '' => __( 'All item types', 'invoicing' ) |
|
592 | - ), |
|
593 | - wpinv_get_item_types() |
|
594 | - ), |
|
595 | - 'name' => 'type', |
|
596 | - 'id' => 'type', |
|
597 | - 'selected' => in_array( $type, wpinv_item_types() ) ? $type : '', |
|
598 | - 'show_option_all' => false, |
|
599 | - 'show_option_none' => false, |
|
600 | - 'class' => 'gdmbx2-text-medium', |
|
601 | - ) |
|
602 | - ); |
|
603 | - |
|
604 | - } |
|
605 | - |
|
606 | - /** |
|
607 | - * Filters the item query. |
|
608 | - */ |
|
609 | - public static function filter_item_query( $query ) { |
|
610 | - |
|
611 | - // modify the query only if it admin and main query. |
|
612 | - if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
613 | - return $query; |
|
614 | - } |
|
615 | - |
|
616 | - // we want to modify the query for our items. |
|
617 | - if ( 'wpi_item' != $query->query['post_type'] ){ |
|
618 | - return $query; |
|
619 | - } |
|
620 | - |
|
621 | - if ( empty( $query->query_vars['meta_query'] ) ) { |
|
622 | - $query->query_vars['meta_query'] = array(); |
|
623 | - } |
|
624 | - |
|
625 | - // Filter vat rule type |
|
625 | + // Filter vat rule type |
|
626 | 626 | if ( ! empty( $_GET['vat_rule'] ) ) { |
627 | 627 | $query->query_vars['meta_query'][] = array( |
628 | 628 | 'key' => '_wpinv_vat_rule', |
@@ -647,94 +647,94 @@ discard block |
||
647 | 647 | 'value' => sanitize_text_field( $_GET['type'] ), |
648 | 648 | 'compare' => '=' |
649 | 649 | ); |
650 | - } |
|
651 | - |
|
652 | - } |
|
653 | - |
|
654 | - /** |
|
655 | - * Reorders items. |
|
656 | - */ |
|
657 | - public static function reorder_items( $vars ) { |
|
658 | - global $typenow; |
|
659 | - |
|
660 | - if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
661 | - return $vars; |
|
662 | - } |
|
663 | - |
|
664 | - // By item type. |
|
665 | - if ( 'type' == $vars['orderby'] ) { |
|
666 | - return array_merge( |
|
667 | - $vars, |
|
668 | - array( |
|
669 | - 'meta_key' => '_wpinv_type', |
|
670 | - 'orderby' => 'meta_value' |
|
671 | - ) |
|
672 | - ); |
|
673 | - } |
|
674 | - |
|
675 | - // By vat class. |
|
676 | - if ( 'vat_class' == $vars['orderby'] ) { |
|
677 | - return array_merge( |
|
678 | - $vars, |
|
679 | - array( |
|
680 | - 'meta_key' => '_wpinv_vat_class', |
|
681 | - 'orderby' => 'meta_value' |
|
682 | - ) |
|
683 | - ); |
|
684 | - } |
|
685 | - |
|
686 | - // By vat rule. |
|
687 | - if ( 'vat_rule' == $vars['orderby'] ) { |
|
688 | - return array_merge( |
|
689 | - $vars, |
|
690 | - array( |
|
691 | - 'meta_key' => '_wpinv_vat_rule', |
|
692 | - 'orderby' => 'meta_value' |
|
693 | - ) |
|
694 | - ); |
|
695 | - } |
|
696 | - |
|
697 | - // By price. |
|
698 | - if ( 'price' == $vars['orderby'] ) { |
|
699 | - return array_merge( |
|
700 | - $vars, |
|
701 | - array( |
|
702 | - 'meta_key' => '_wpinv_price', |
|
703 | - 'orderby' => 'meta_value_num' |
|
704 | - ) |
|
705 | - ); |
|
706 | - } |
|
707 | - |
|
708 | - return $vars; |
|
709 | - |
|
710 | - } |
|
711 | - |
|
712 | - /** |
|
713 | - * Fired when deleting a post. |
|
714 | - */ |
|
715 | - public static function delete_post( $post_id ) { |
|
716 | - |
|
717 | - switch ( get_post_type( $post_id ) ) { |
|
718 | - |
|
719 | - case 'wpi_item' : |
|
720 | - do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
721 | - break; |
|
722 | - |
|
723 | - case 'wpi_payment_form' : |
|
724 | - do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
725 | - break; |
|
726 | - |
|
727 | - case 'wpi_discount' : |
|
728 | - do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
729 | - break; |
|
730 | - |
|
731 | - case 'wpi_invoice' : |
|
732 | - $invoice = new WPInv_Invoice( $post_id ); |
|
733 | - do_action( "getpaid_before_delete_invoice", $invoice ); |
|
734 | - $invoice->get_data_store()->delete_items( $invoice ); |
|
735 | - $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
736 | - break; |
|
737 | - } |
|
738 | - } |
|
650 | + } |
|
651 | + |
|
652 | + } |
|
653 | + |
|
654 | + /** |
|
655 | + * Reorders items. |
|
656 | + */ |
|
657 | + public static function reorder_items( $vars ) { |
|
658 | + global $typenow; |
|
659 | + |
|
660 | + if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
661 | + return $vars; |
|
662 | + } |
|
663 | + |
|
664 | + // By item type. |
|
665 | + if ( 'type' == $vars['orderby'] ) { |
|
666 | + return array_merge( |
|
667 | + $vars, |
|
668 | + array( |
|
669 | + 'meta_key' => '_wpinv_type', |
|
670 | + 'orderby' => 'meta_value' |
|
671 | + ) |
|
672 | + ); |
|
673 | + } |
|
674 | + |
|
675 | + // By vat class. |
|
676 | + if ( 'vat_class' == $vars['orderby'] ) { |
|
677 | + return array_merge( |
|
678 | + $vars, |
|
679 | + array( |
|
680 | + 'meta_key' => '_wpinv_vat_class', |
|
681 | + 'orderby' => 'meta_value' |
|
682 | + ) |
|
683 | + ); |
|
684 | + } |
|
685 | + |
|
686 | + // By vat rule. |
|
687 | + if ( 'vat_rule' == $vars['orderby'] ) { |
|
688 | + return array_merge( |
|
689 | + $vars, |
|
690 | + array( |
|
691 | + 'meta_key' => '_wpinv_vat_rule', |
|
692 | + 'orderby' => 'meta_value' |
|
693 | + ) |
|
694 | + ); |
|
695 | + } |
|
696 | + |
|
697 | + // By price. |
|
698 | + if ( 'price' == $vars['orderby'] ) { |
|
699 | + return array_merge( |
|
700 | + $vars, |
|
701 | + array( |
|
702 | + 'meta_key' => '_wpinv_price', |
|
703 | + 'orderby' => 'meta_value_num' |
|
704 | + ) |
|
705 | + ); |
|
706 | + } |
|
707 | + |
|
708 | + return $vars; |
|
709 | + |
|
710 | + } |
|
711 | + |
|
712 | + /** |
|
713 | + * Fired when deleting a post. |
|
714 | + */ |
|
715 | + public static function delete_post( $post_id ) { |
|
716 | + |
|
717 | + switch ( get_post_type( $post_id ) ) { |
|
718 | + |
|
719 | + case 'wpi_item' : |
|
720 | + do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
721 | + break; |
|
722 | + |
|
723 | + case 'wpi_payment_form' : |
|
724 | + do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
725 | + break; |
|
726 | + |
|
727 | + case 'wpi_discount' : |
|
728 | + do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
729 | + break; |
|
730 | + |
|
731 | + case 'wpi_invoice' : |
|
732 | + $invoice = new WPInv_Invoice( $post_id ); |
|
733 | + do_action( "getpaid_before_delete_invoice", $invoice ); |
|
734 | + $invoice->get_data_store()->delete_items( $invoice ); |
|
735 | + $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
736 | + break; |
|
737 | + } |
|
738 | + } |
|
739 | 739 | |
740 | 740 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Post types Admin Class |
@@ -21,68 +21,68 @@ discard block |
||
21 | 21 | GetPaid_Metaboxes::init(); |
22 | 22 | |
23 | 23 | // Filter the post updated messages. |
24 | - add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
24 | + add_filter('post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages'); |
|
25 | 25 | |
26 | 26 | // Filter post actions. |
27 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
27 | + add_filter('post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2); |
|
28 | 28 | |
29 | 29 | // Invoice table columns. |
30 | - add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
31 | - add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
30 | + add_filter('manage_wpi_invoice_posts_columns', array(__CLASS__, 'invoice_columns'), 100); |
|
31 | + add_action('manage_wpi_invoice_posts_custom_column', array(__CLASS__, 'display_invoice_columns'), 10, 2); |
|
32 | 32 | |
33 | 33 | // Items table columns. |
34 | - add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
35 | - add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
36 | - add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
37 | - add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
38 | - add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
39 | - add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
34 | + add_filter('manage_wpi_item_posts_columns', array(__CLASS__, 'item_columns'), 100); |
|
35 | + add_filter('manage_edit-wpi_item_sortable_columns', array(__CLASS__, 'sortable_item_columns'), 20); |
|
36 | + add_action('manage_wpi_item_posts_custom_column', array(__CLASS__, 'display_item_columns'), 10, 2); |
|
37 | + add_action('restrict_manage_posts', array(__CLASS__, 'add_item_filters'), 100); |
|
38 | + add_action('parse_query', array(__CLASS__, 'filter_item_query'), 100); |
|
39 | + add_action('request', array(__CLASS__, 'reorder_items'), 100); |
|
40 | 40 | |
41 | 41 | // Payment forms columns. |
42 | - add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
43 | - add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
44 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
42 | + add_filter('manage_wpi_payment_form_posts_columns', array(__CLASS__, 'payment_form_columns'), 100); |
|
43 | + add_action('manage_wpi_payment_form_posts_custom_column', array(__CLASS__, 'display_payment_form_columns'), 10, 2); |
|
44 | + add_filter('display_post_states', array(__CLASS__, 'filter_payment_form_state'), 10, 2); |
|
45 | 45 | |
46 | 46 | // Discount table columns. |
47 | - add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
47 | + add_filter('manage_wpi_discount_posts_columns', array(__CLASS__, 'discount_columns'), 100); |
|
48 | 48 | |
49 | 49 | // Deleting posts. |
50 | - add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
51 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
50 | + add_action('delete_post', array(__CLASS__, 'delete_post')); |
|
51 | + add_filter('display_post_states', array(__CLASS__, 'filter_discount_state'), 10, 2); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
55 | 55 | * Post updated messages. |
56 | 56 | */ |
57 | - public static function post_updated_messages( $messages ) { |
|
57 | + public static function post_updated_messages($messages) { |
|
58 | 58 | global $post; |
59 | 59 | |
60 | 60 | $messages['wpi_discount'] = array( |
61 | 61 | 0 => '', |
62 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
63 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
64 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
65 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
66 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
67 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
68 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
69 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
70 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
71 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
62 | + 1 => __('Discount updated.', 'invoicing'), |
|
63 | + 2 => __('Custom field updated.', 'invoicing'), |
|
64 | + 3 => __('Custom field deleted.', 'invoicing'), |
|
65 | + 4 => __('Discount updated.', 'invoicing'), |
|
66 | + 5 => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false, |
|
67 | + 6 => __('Discount updated.', 'invoicing'), |
|
68 | + 7 => __('Discount saved.', 'invoicing'), |
|
69 | + 8 => __('Discount submitted.', 'invoicing'), |
|
70 | + 9 => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))), |
|
71 | + 10 => __('Discount draft updated.', 'invoicing'), |
|
72 | 72 | ); |
73 | 73 | |
74 | 74 | $messages['wpi_payment_form'] = array( |
75 | 75 | 0 => '', |
76 | - 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
77 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
78 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
79 | - 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
80 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
81 | - 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
82 | - 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
83 | - 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
84 | - 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
85 | - 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
76 | + 1 => __('Payment Form updated.', 'invoicing'), |
|
77 | + 2 => __('Custom field updated.', 'invoicing'), |
|
78 | + 3 => __('Custom field deleted.', 'invoicing'), |
|
79 | + 4 => __('Payment Form updated.', 'invoicing'), |
|
80 | + 5 => isset($_GET['revision']) ? wp_sprintf(__('Payment Form restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false, |
|
81 | + 6 => __('Payment Form updated.', 'invoicing'), |
|
82 | + 7 => __('Payment Form saved.', 'invoicing'), |
|
83 | + 8 => __('Payment Form submitted.', 'invoicing'), |
|
84 | + 9 => wp_sprintf(__('Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))), |
|
85 | + 10 => __('Payment Form draft updated.', 'invoicing'), |
|
86 | 86 | ); |
87 | 87 | |
88 | 88 | return $messages; |
@@ -92,14 +92,14 @@ discard block |
||
92 | 92 | /** |
93 | 93 | * Post row actions. |
94 | 94 | */ |
95 | - public static function post_row_actions( $actions, $post ) { |
|
95 | + public static function post_row_actions($actions, $post) { |
|
96 | 96 | |
97 | - $post = get_post( $post ); |
|
97 | + $post = get_post($post); |
|
98 | 98 | |
99 | 99 | // We do not want to edit the default payment form. |
100 | - if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) { |
|
101 | - unset( $actions['trash'] ); |
|
102 | - unset( $actions['inline hide-if-no-js'] ); |
|
100 | + if ('wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form()) { |
|
101 | + unset($actions['trash']); |
|
102 | + unset($actions['inline hide-if-no-js']); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | return $actions; |
@@ -108,51 +108,51 @@ discard block |
||
108 | 108 | /** |
109 | 109 | * Returns an array of invoice table columns. |
110 | 110 | */ |
111 | - public static function invoice_columns( $columns ) { |
|
111 | + public static function invoice_columns($columns) { |
|
112 | 112 | |
113 | 113 | $columns = array( |
114 | 114 | 'cb' => $columns['cb'], |
115 | - 'number' => __( 'Invoice', 'invoicing' ), |
|
116 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
117 | - 'invoice_date' => __( 'Date', 'invoicing' ), |
|
118 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
119 | - 'recurring' => __( 'Recurring', 'invoicing' ), |
|
120 | - 'status' => __( 'Status', 'invoicing' ), |
|
121 | - 'wpi_actions' => __( 'Actions', 'invoicing' ), |
|
115 | + 'number' => __('Invoice', 'invoicing'), |
|
116 | + 'customer' => __('Customer', 'invoicing'), |
|
117 | + 'invoice_date' => __('Date', 'invoicing'), |
|
118 | + 'amount' => __('Amount', 'invoicing'), |
|
119 | + 'recurring' => __('Recurring', 'invoicing'), |
|
120 | + 'status' => __('Status', 'invoicing'), |
|
121 | + 'wpi_actions' => __('Actions', 'invoicing'), |
|
122 | 122 | ); |
123 | 123 | |
124 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
124 | + return apply_filters('wpi_invoice_table_columns', $columns); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | 128 | * Displays invoice table columns. |
129 | 129 | */ |
130 | - public static function display_invoice_columns( $column_name, $post_id ) { |
|
130 | + public static function display_invoice_columns($column_name, $post_id) { |
|
131 | 131 | |
132 | - $invoice = new WPInv_Invoice( $post_id ); |
|
132 | + $invoice = new WPInv_Invoice($post_id); |
|
133 | 133 | |
134 | - switch ( $column_name ) { |
|
134 | + switch ($column_name) { |
|
135 | 135 | |
136 | 136 | case 'invoice_date' : |
137 | - $date_time = esc_attr( $invoice->get_created_date() ); |
|
138 | - $date = getpaid_format_date_value( $date_time ); |
|
137 | + $date_time = esc_attr($invoice->get_created_date()); |
|
138 | + $date = getpaid_format_date_value($date_time); |
|
139 | 139 | echo "<span title='$date_time'>$date</span>"; |
140 | 140 | break; |
141 | 141 | |
142 | 142 | case 'amount' : |
143 | 143 | |
144 | 144 | $amount = $invoice->get_total(); |
145 | - $formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() ); |
|
145 | + $formated_amount = wpinv_price(wpinv_format_amount($amount), $invoice->get_currency()); |
|
146 | 146 | |
147 | - if ( $invoice->is_refunded() ) { |
|
148 | - $refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() ); |
|
147 | + if ($invoice->is_refunded()) { |
|
148 | + $refunded_amount = wpinv_price(wpinv_format_amount(0), $invoice->get_currency()); |
|
149 | 149 | echo "<del>$formated_amount</del> <ins>$refunded_amount</ins>"; |
150 | 150 | } else { |
151 | 151 | |
152 | 152 | $discount = $invoice->get_total_discount(); |
153 | 153 | |
154 | - if ( ! empty( $discount ) ) { |
|
155 | - $new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() ); |
|
154 | + if (!empty($discount)) { |
|
155 | + $new_amount = wpinv_price(wpinv_format_amount($amount + $discount), $invoice->get_currency()); |
|
156 | 156 | echo "<del>$new_amount</del> <ins>$formated_amount</ins>"; |
157 | 157 | } else { |
158 | 158 | echo $formated_amount; |
@@ -163,13 +163,13 @@ discard block |
||
163 | 163 | break; |
164 | 164 | |
165 | 165 | case 'status' : |
166 | - $status = sanitize_text_field( $invoice->get_status() ); |
|
167 | - $status_label = sanitize_text_field( $invoice->get_status_nicename() ); |
|
166 | + $status = sanitize_text_field($invoice->get_status()); |
|
167 | + $status_label = sanitize_text_field($invoice->get_status_nicename()); |
|
168 | 168 | |
169 | 169 | // If it is paid, show the gateway title. |
170 | - if ( $invoice->is_paid() ) { |
|
171 | - $gateway = sanitize_text_field( $invoice->get_gateway_title() ); |
|
172 | - $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
170 | + if ($invoice->is_paid()) { |
|
171 | + $gateway = sanitize_text_field($invoice->get_gateway_title()); |
|
172 | + $gateway = wp_sprintf(esc_attr__('Paid via %s', 'invoicing'), $gateway); |
|
173 | 173 | |
174 | 174 | echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
175 | 175 | } else { |
@@ -177,22 +177,22 @@ discard block |
||
177 | 177 | } |
178 | 178 | |
179 | 179 | // If it is not paid, display the overdue and view status. |
180 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
180 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
181 | 181 | |
182 | 182 | // Invoice view status. |
183 | - if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
184 | - echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
183 | + if (wpinv_is_invoice_viewed($invoice->get_id())) { |
|
184 | + echo ' <i class="fa fa-eye wpi-help-tip" title="' . esc_attr__('Viewed by Customer', 'invoicing') . '"></i>'; |
|
185 | 185 | } else { |
186 | - echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
186 | + echo ' <i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__('Not Viewed by Customer', 'invoicing') . '"></i>'; |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | // Display the overview status. |
190 | - if ( wpinv_get_option( 'overdue_active' ) ) { |
|
190 | + if (wpinv_get_option('overdue_active')) { |
|
191 | 191 | $due_date = $invoice->get_due_date(); |
192 | - $fomatted = getpaid_format_date( $due_date ); |
|
192 | + $fomatted = getpaid_format_date($due_date); |
|
193 | 193 | |
194 | - if ( ! empty( $fomatted ) ) { |
|
195 | - $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted ); |
|
194 | + if (!empty($fomatted)) { |
|
195 | + $date = wp_sprintf(__('Due %s', 'invoicing'), $fomatted); |
|
196 | 196 | echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"; |
197 | 197 | } |
198 | 198 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | |
204 | 204 | case 'recurring': |
205 | 205 | |
206 | - if ( $invoice->is_recurring() ) { |
|
206 | + if ($invoice->is_recurring()) { |
|
207 | 207 | echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
208 | 208 | } else { |
209 | 209 | echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
@@ -212,9 +212,9 @@ discard block |
||
212 | 212 | |
213 | 213 | case 'number' : |
214 | 214 | |
215 | - $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
216 | - $invoice_number = sanitize_text_field( $invoice->get_number() ); |
|
217 | - $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
215 | + $edit_link = esc_url(get_edit_post_link($invoice->get_id())); |
|
216 | + $invoice_number = sanitize_text_field($invoice->get_number()); |
|
217 | + $invoice_details = esc_attr__('View Invoice Details', 'invoicing'); |
|
218 | 218 | |
219 | 219 | echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
220 | 220 | |
@@ -224,13 +224,13 @@ discard block |
||
224 | 224 | |
225 | 225 | $customer_name = $invoice->get_user_full_name(); |
226 | 226 | |
227 | - if ( empty( $customer_name ) ) { |
|
227 | + if (empty($customer_name)) { |
|
228 | 228 | $customer_name = $invoice->get_email(); |
229 | 229 | } |
230 | 230 | |
231 | - if ( ! empty( $customer_name ) ) { |
|
232 | - $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
233 | - $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
231 | + if (!empty($customer_name)) { |
|
232 | + $customer_details = esc_attr__('View Customer Details', 'invoicing'); |
|
233 | + $view_link = esc_url(add_query_arg('user_id', $invoice->get_user_id(), admin_url('user-edit.php'))); |
|
234 | 234 | echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
235 | 235 | } else { |
236 | 236 | echo '<div>—</div>'; |
@@ -240,12 +240,12 @@ discard block |
||
240 | 240 | |
241 | 241 | case 'wpi_actions' : |
242 | 242 | |
243 | - if ( $invoice->is_draft() ) { |
|
243 | + if ($invoice->is_draft()) { |
|
244 | 244 | return; |
245 | 245 | } |
246 | 246 | |
247 | - $url = esc_url( $invoice->get_view_url() ); |
|
248 | - $print = esc_attr__( 'Print invoice', 'invoicing' ); |
|
247 | + $url = esc_url($invoice->get_view_url()); |
|
248 | + $print = esc_attr__('Print invoice', 'invoicing'); |
|
249 | 249 | echo " <a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>"; |
250 | 250 | |
251 | 251 | $url = esc_url( |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | ) |
262 | 262 | ); |
263 | 263 | |
264 | - $send = esc_attr__( 'Send invoice to customer', 'invoicing' ); |
|
264 | + $send = esc_attr__('Send invoice to customer', 'invoicing'); |
|
265 | 265 | echo " <a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>"; |
266 | 266 | |
267 | 267 | break; |
@@ -272,50 +272,50 @@ discard block |
||
272 | 272 | /** |
273 | 273 | * Returns an array of payment forms table columns. |
274 | 274 | */ |
275 | - public static function payment_form_columns( $columns ) { |
|
275 | + public static function payment_form_columns($columns) { |
|
276 | 276 | |
277 | 277 | $columns = array( |
278 | 278 | 'cb' => $columns['cb'], |
279 | - 'title' => __( 'Name', 'invoicing' ), |
|
280 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
281 | - 'earnings' => __( 'Revenue', 'invoicing' ), |
|
282 | - 'refunds' => __( 'Refunded', 'invoicing' ), |
|
283 | - 'items' => __( 'Items', 'invoicing' ), |
|
284 | - 'date' => __( 'Date', 'invoicing' ), |
|
279 | + 'title' => __('Name', 'invoicing'), |
|
280 | + 'shortcode' => __('Shortcode', 'invoicing'), |
|
281 | + 'earnings' => __('Revenue', 'invoicing'), |
|
282 | + 'refunds' => __('Refunded', 'invoicing'), |
|
283 | + 'items' => __('Items', 'invoicing'), |
|
284 | + 'date' => __('Date', 'invoicing'), |
|
285 | 285 | ); |
286 | 286 | |
287 | - return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
287 | + return apply_filters('wpi_payment_form_table_columns', $columns); |
|
288 | 288 | |
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
292 | 292 | * Displays payment form table columns. |
293 | 293 | */ |
294 | - public static function display_payment_form_columns( $column_name, $post_id ) { |
|
294 | + public static function display_payment_form_columns($column_name, $post_id) { |
|
295 | 295 | |
296 | 296 | // Retrieve the payment form. |
297 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
297 | + $form = new GetPaid_Payment_Form($post_id); |
|
298 | 298 | |
299 | - switch ( $column_name ) { |
|
299 | + switch ($column_name) { |
|
300 | 300 | |
301 | 301 | case 'earnings' : |
302 | - echo wpinv_price( wpinv_format_amount( $form->get_earned() ) ); |
|
302 | + echo wpinv_price(wpinv_format_amount($form->get_earned())); |
|
303 | 303 | break; |
304 | 304 | |
305 | 305 | case 'refunds' : |
306 | - echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
306 | + echo wpinv_price(wpinv_format_amount($form->get_refunded())); |
|
307 | 307 | break; |
308 | 308 | |
309 | 309 | case 'refunds' : |
310 | - echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
310 | + echo wpinv_price(wpinv_format_amount($form->get_refunded())); |
|
311 | 311 | break; |
312 | 312 | |
313 | 313 | case 'shortcode' : |
314 | 314 | |
315 | - if ( $form->is_default() ) { |
|
315 | + if ($form->is_default()) { |
|
316 | 316 | echo '—'; |
317 | 317 | } else { |
318 | - echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
318 | + echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr($form->get_id()) . ']" style="width: 100%;" readonly/>'; |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | break; |
@@ -324,29 +324,29 @@ discard block |
||
324 | 324 | |
325 | 325 | $items = $form->get_items(); |
326 | 326 | |
327 | - if ( $form->is_default() || empty( $items ) ) { |
|
327 | + if ($form->is_default() || empty($items)) { |
|
328 | 328 | echo '—'; |
329 | 329 | return; |
330 | 330 | } |
331 | 331 | |
332 | 332 | $_items = array(); |
333 | 333 | |
334 | - foreach ( $items as $item ) { |
|
334 | + foreach ($items as $item) { |
|
335 | 335 | $url = $item->get_edit_url(); |
336 | 336 | |
337 | - if ( empty( $url ) ) { |
|
338 | - $_items[] = sanitize_text_field( $item->get_name() ); |
|
337 | + if (empty($url)) { |
|
338 | + $_items[] = sanitize_text_field($item->get_name()); |
|
339 | 339 | } else { |
340 | 340 | $_items[] = sprintf( |
341 | 341 | '<a href="%s">%s</a>', |
342 | - esc_url( $url ), |
|
343 | - sanitize_text_field( $item->get_name() ) |
|
342 | + esc_url($url), |
|
343 | + sanitize_text_field($item->get_name()) |
|
344 | 344 | ); |
345 | 345 | } |
346 | 346 | |
347 | 347 | } |
348 | 348 | |
349 | - echo implode( '<br>', $_items ); |
|
349 | + echo implode('<br>', $_items); |
|
350 | 350 | |
351 | 351 | break; |
352 | 352 | |
@@ -357,10 +357,10 @@ discard block |
||
357 | 357 | /** |
358 | 358 | * Filters post states. |
359 | 359 | */ |
360 | - public static function filter_payment_form_state( $post_states, $post ) { |
|
360 | + public static function filter_payment_form_state($post_states, $post) { |
|
361 | 361 | |
362 | - if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
363 | - $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
362 | + if ('wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID) { |
|
363 | + $post_states['default_form'] = __('Default Payment Form', 'invoicing'); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | return $post_states; |
@@ -370,35 +370,35 @@ discard block |
||
370 | 370 | /** |
371 | 371 | * Returns an array of coupon table columns. |
372 | 372 | */ |
373 | - public static function discount_columns( $columns ) { |
|
373 | + public static function discount_columns($columns) { |
|
374 | 374 | |
375 | 375 | $columns = array( |
376 | 376 | 'cb' => $columns['cb'], |
377 | - 'title' => __( 'Name', 'invoicing' ), |
|
378 | - 'code' => __( 'Code', 'invoicing' ), |
|
379 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
380 | - 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
381 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
382 | - 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
377 | + 'title' => __('Name', 'invoicing'), |
|
378 | + 'code' => __('Code', 'invoicing'), |
|
379 | + 'amount' => __('Amount', 'invoicing'), |
|
380 | + 'usage' => __('Usage / Limit', 'invoicing'), |
|
381 | + 'start_date' => __('Start Date', 'invoicing'), |
|
382 | + 'expiry_date' => __('Expiry Date', 'invoicing'), |
|
383 | 383 | ); |
384 | 384 | |
385 | - return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
385 | + return apply_filters('wpi_discount_table_columns', $columns); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | /** |
389 | 389 | * Filters post states. |
390 | 390 | */ |
391 | - public static function filter_discount_state( $post_states, $post ) { |
|
391 | + public static function filter_discount_state($post_states, $post) { |
|
392 | 392 | |
393 | - if ( 'wpi_discount' == $post->post_type ) { |
|
393 | + if ('wpi_discount' == $post->post_type) { |
|
394 | 394 | |
395 | - $discount = new WPInv_Discount( $post ); |
|
395 | + $discount = new WPInv_Discount($post); |
|
396 | 396 | |
397 | 397 | $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
398 | 398 | |
399 | - if ( $status != 'publish' ) { |
|
399 | + if ($status != 'publish') { |
|
400 | 400 | return array( |
401 | - 'discount_status' => wpinv_discount_status( $status ), |
|
401 | + 'discount_status' => wpinv_discount_status($status), |
|
402 | 402 | ); |
403 | 403 | } |
404 | 404 | |
@@ -413,34 +413,34 @@ discard block |
||
413 | 413 | /** |
414 | 414 | * Returns an array of items table columns. |
415 | 415 | */ |
416 | - public static function item_columns( $columns ) { |
|
416 | + public static function item_columns($columns) { |
|
417 | 417 | global $wpinv_euvat; |
418 | 418 | |
419 | 419 | $columns = array( |
420 | 420 | 'cb' => $columns['cb'], |
421 | - 'title' => __( 'Name', 'invoicing' ), |
|
422 | - 'price' => __( 'Price', 'invoicing' ), |
|
423 | - 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
424 | - 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
425 | - 'type' => __( 'Type', 'invoicing' ), |
|
426 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
421 | + 'title' => __('Name', 'invoicing'), |
|
422 | + 'price' => __('Price', 'invoicing'), |
|
423 | + 'vat_rule' => __('VAT rule', 'invoicing'), |
|
424 | + 'vat_class' => __('VAT class', 'invoicing'), |
|
425 | + 'type' => __('Type', 'invoicing'), |
|
426 | + 'shortcode' => __('Shortcode', 'invoicing'), |
|
427 | 427 | ); |
428 | 428 | |
429 | - if ( ! $wpinv_euvat->allow_vat_rules() ) { |
|
430 | - unset( $columns['vat_rule'] ); |
|
429 | + if (!$wpinv_euvat->allow_vat_rules()) { |
|
430 | + unset($columns['vat_rule']); |
|
431 | 431 | } |
432 | 432 | |
433 | - if ( ! $wpinv_euvat->allow_vat_classes() ) { |
|
434 | - unset( $columns['vat_class'] ); |
|
433 | + if (!$wpinv_euvat->allow_vat_classes()) { |
|
434 | + unset($columns['vat_class']); |
|
435 | 435 | } |
436 | 436 | |
437 | - return apply_filters( 'wpi_item_table_columns', $columns ); |
|
437 | + return apply_filters('wpi_item_table_columns', $columns); |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | /** |
441 | 441 | * Returns an array of sortable items table columns. |
442 | 442 | */ |
443 | - public static function sortable_item_columns( $columns ) { |
|
443 | + public static function sortable_item_columns($columns) { |
|
444 | 444 | |
445 | 445 | return array_merge( |
446 | 446 | $columns, |
@@ -457,50 +457,50 @@ discard block |
||
457 | 457 | /** |
458 | 458 | * Displays items table columns. |
459 | 459 | */ |
460 | - public static function display_item_columns( $column_name, $post_id ) { |
|
460 | + public static function display_item_columns($column_name, $post_id) { |
|
461 | 461 | global $wpinv_euvat; |
462 | 462 | |
463 | - $item = new WPInv_Item( $post_id ); |
|
463 | + $item = new WPInv_Item($post_id); |
|
464 | 464 | |
465 | - switch ( $column_name ) { |
|
465 | + switch ($column_name) { |
|
466 | 466 | |
467 | 467 | case 'price' : |
468 | 468 | |
469 | - if ( ! $item->is_recurring() ) { |
|
469 | + if (!$item->is_recurring()) { |
|
470 | 470 | echo $item->get_the_price(); |
471 | 471 | break; |
472 | 472 | } |
473 | 473 | |
474 | 474 | $price = wp_sprintf( |
475 | - __( '%s / %s', 'invoicing' ), |
|
475 | + __('%s / %s', 'invoicing'), |
|
476 | 476 | $item->get_the_price(), |
477 | - getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
477 | + getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), '') |
|
478 | 478 | ); |
479 | 479 | |
480 | - if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
480 | + if ($item->get_the_price() == $item->get_the_initial_price()) { |
|
481 | 481 | echo $price; |
482 | 482 | break; |
483 | 483 | } |
484 | 484 | |
485 | 485 | echo $item->get_the_initial_price(); |
486 | 486 | |
487 | - echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
487 | + echo '<span class="meta">' . wp_sprintf(__('then %s', 'invoicing'), $price) . '</span>'; |
|
488 | 488 | break; |
489 | 489 | |
490 | 490 | case 'vat_rule' : |
491 | - echo $wpinv_euvat->item_rule_label( $item->get_id() ); |
|
491 | + echo $wpinv_euvat->item_rule_label($item->get_id()); |
|
492 | 492 | break; |
493 | 493 | |
494 | 494 | case 'vat_class' : |
495 | - echo $wpinv_euvat->item_class_label( $item->get_id() ); |
|
495 | + echo $wpinv_euvat->item_class_label($item->get_id()); |
|
496 | 496 | break; |
497 | 497 | |
498 | 498 | case 'shortcode' : |
499 | - echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
499 | + echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr($item->get_id()) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
500 | 500 | break; |
501 | 501 | |
502 | 502 | case 'type' : |
503 | - echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
503 | + echo wpinv_item_type($item->get_id()) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
504 | 504 | break; |
505 | 505 | |
506 | 506 | } |
@@ -510,22 +510,22 @@ discard block |
||
510 | 510 | /** |
511 | 511 | * Lets users filter items using taxes. |
512 | 512 | */ |
513 | - public static function add_item_filters( $post_type ) { |
|
513 | + public static function add_item_filters($post_type) { |
|
514 | 514 | $wpinv_euvat = getpaid_tax(); |
515 | 515 | |
516 | 516 | // Abort if we're not dealing with items. |
517 | - if ( $post_type != 'wpi_item' ) { |
|
517 | + if ($post_type != 'wpi_item') { |
|
518 | 518 | return; |
519 | 519 | } |
520 | 520 | |
521 | 521 | // Filter by vat rules. |
522 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
522 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
523 | 523 | |
524 | 524 | // Sanitize selected vat rule. |
525 | 525 | $vat_rule = ''; |
526 | 526 | $vat_rules = $wpinv_euvat->get_rules(); |
527 | - if ( isset( $_GET['vat_rule'] ) ) { |
|
528 | - $vat_rule = $_GET['vat_rule']; |
|
527 | + if (isset($_GET['vat_rule'])) { |
|
528 | + $vat_rule = $_GET['vat_rule']; |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | // Filter by VAT rule. |
@@ -533,13 +533,13 @@ discard block |
||
533 | 533 | array( |
534 | 534 | 'options' => array_merge( |
535 | 535 | array( |
536 | - '' => __( 'All VAT rules', 'invoicing' ) |
|
536 | + '' => __('All VAT rules', 'invoicing') |
|
537 | 537 | ), |
538 | 538 | $vat_rules |
539 | 539 | ), |
540 | 540 | 'name' => 'vat_rule', |
541 | 541 | 'id' => 'vat_rule', |
542 | - 'selected' => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '', |
|
542 | + 'selected' => in_array($vat_rule, array_keys($vat_rules)) ? $vat_rule : '', |
|
543 | 543 | 'show_option_all' => false, |
544 | 544 | 'show_option_none' => false, |
545 | 545 | 'class' => 'gdmbx2-text-medium', |
@@ -550,26 +550,26 @@ discard block |
||
550 | 550 | } |
551 | 551 | |
552 | 552 | // Filter by vat class. |
553 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
553 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
554 | 554 | |
555 | 555 | // Sanitize selected vat rule. |
556 | 556 | $vat_class = ''; |
557 | 557 | $vat_classes = $wpinv_euvat->get_all_classes(); |
558 | - if ( isset( $_GET['vat_class'] ) ) { |
|
559 | - $vat_class = $_GET['vat_class']; |
|
558 | + if (isset($_GET['vat_class'])) { |
|
559 | + $vat_class = $_GET['vat_class']; |
|
560 | 560 | } |
561 | 561 | |
562 | 562 | echo wpinv_html_select( |
563 | 563 | array( |
564 | 564 | 'options' => array_merge( |
565 | 565 | array( |
566 | - '' => __( 'All VAT classes', 'invoicing' ) |
|
566 | + '' => __('All VAT classes', 'invoicing') |
|
567 | 567 | ), |
568 | 568 | $vat_classes |
569 | 569 | ), |
570 | 570 | 'name' => 'vat_class', |
571 | 571 | 'id' => 'vat_class', |
572 | - 'selected' => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '', |
|
572 | + 'selected' => in_array($vat_class, array_keys($vat_classes)) ? $vat_class : '', |
|
573 | 573 | 'show_option_all' => false, |
574 | 574 | 'show_option_none' => false, |
575 | 575 | 'class' => 'gdmbx2-text-medium', |
@@ -579,22 +579,22 @@ discard block |
||
579 | 579 | } |
580 | 580 | |
581 | 581 | // Filter by item type. |
582 | - $type = ''; |
|
583 | - if ( isset( $_GET['type'] ) ) { |
|
584 | - $type = $_GET['type']; |
|
582 | + $type = ''; |
|
583 | + if (isset($_GET['type'])) { |
|
584 | + $type = $_GET['type']; |
|
585 | 585 | } |
586 | 586 | |
587 | 587 | echo wpinv_html_select( |
588 | 588 | array( |
589 | 589 | 'options' => array_merge( |
590 | 590 | array( |
591 | - '' => __( 'All item types', 'invoicing' ) |
|
591 | + '' => __('All item types', 'invoicing') |
|
592 | 592 | ), |
593 | 593 | wpinv_get_item_types() |
594 | 594 | ), |
595 | 595 | 'name' => 'type', |
596 | 596 | 'id' => 'type', |
597 | - 'selected' => in_array( $type, wpinv_item_types() ) ? $type : '', |
|
597 | + 'selected' => in_array($type, wpinv_item_types()) ? $type : '', |
|
598 | 598 | 'show_option_all' => false, |
599 | 599 | 'show_option_none' => false, |
600 | 600 | 'class' => 'gdmbx2-text-medium', |
@@ -606,45 +606,45 @@ discard block |
||
606 | 606 | /** |
607 | 607 | * Filters the item query. |
608 | 608 | */ |
609 | - public static function filter_item_query( $query ) { |
|
609 | + public static function filter_item_query($query) { |
|
610 | 610 | |
611 | 611 | // modify the query only if it admin and main query. |
612 | - if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
612 | + if (!(is_admin() && $query->is_main_query())) { |
|
613 | 613 | return $query; |
614 | 614 | } |
615 | 615 | |
616 | 616 | // we want to modify the query for our items. |
617 | - if ( 'wpi_item' != $query->query['post_type'] ){ |
|
617 | + if ('wpi_item' != $query->query['post_type']) { |
|
618 | 618 | return $query; |
619 | 619 | } |
620 | 620 | |
621 | - if ( empty( $query->query_vars['meta_query'] ) ) { |
|
621 | + if (empty($query->query_vars['meta_query'])) { |
|
622 | 622 | $query->query_vars['meta_query'] = array(); |
623 | 623 | } |
624 | 624 | |
625 | 625 | // Filter vat rule type |
626 | - if ( ! empty( $_GET['vat_rule'] ) ) { |
|
626 | + if (!empty($_GET['vat_rule'])) { |
|
627 | 627 | $query->query_vars['meta_query'][] = array( |
628 | 628 | 'key' => '_wpinv_vat_rule', |
629 | - 'value' => sanitize_text_field( $_GET['vat_rule'] ), |
|
629 | + 'value' => sanitize_text_field($_GET['vat_rule']), |
|
630 | 630 | 'compare' => '=' |
631 | 631 | ); |
632 | 632 | } |
633 | 633 | |
634 | 634 | // Filter vat class |
635 | - if ( ! empty( $_GET['vat_class'] ) ) { |
|
635 | + if (!empty($_GET['vat_class'])) { |
|
636 | 636 | $query->query_vars['meta_query'][] = array( |
637 | 637 | 'key' => '_wpinv_vat_class', |
638 | - 'value' => sanitize_text_field( $_GET['vat_class'] ), |
|
638 | + 'value' => sanitize_text_field($_GET['vat_class']), |
|
639 | 639 | 'compare' => '=' |
640 | 640 | ); |
641 | 641 | } |
642 | 642 | |
643 | 643 | // Filter item type |
644 | - if ( ! empty( $_GET['type'] ) ) { |
|
644 | + if (!empty($_GET['type'])) { |
|
645 | 645 | $query->query_vars['meta_query'][] = array( |
646 | 646 | 'key' => '_wpinv_type', |
647 | - 'value' => sanitize_text_field( $_GET['type'] ), |
|
647 | + 'value' => sanitize_text_field($_GET['type']), |
|
648 | 648 | 'compare' => '=' |
649 | 649 | ); |
650 | 650 | } |
@@ -654,15 +654,15 @@ discard block |
||
654 | 654 | /** |
655 | 655 | * Reorders items. |
656 | 656 | */ |
657 | - public static function reorder_items( $vars ) { |
|
657 | + public static function reorder_items($vars) { |
|
658 | 658 | global $typenow; |
659 | 659 | |
660 | - if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
660 | + if ('wpi_item' !== $typenow || empty($vars['orderby'])) { |
|
661 | 661 | return $vars; |
662 | 662 | } |
663 | 663 | |
664 | 664 | // By item type. |
665 | - if ( 'type' == $vars['orderby'] ) { |
|
665 | + if ('type' == $vars['orderby']) { |
|
666 | 666 | return array_merge( |
667 | 667 | $vars, |
668 | 668 | array( |
@@ -673,7 +673,7 @@ discard block |
||
673 | 673 | } |
674 | 674 | |
675 | 675 | // By vat class. |
676 | - if ( 'vat_class' == $vars['orderby'] ) { |
|
676 | + if ('vat_class' == $vars['orderby']) { |
|
677 | 677 | return array_merge( |
678 | 678 | $vars, |
679 | 679 | array( |
@@ -684,7 +684,7 @@ discard block |
||
684 | 684 | } |
685 | 685 | |
686 | 686 | // By vat rule. |
687 | - if ( 'vat_rule' == $vars['orderby'] ) { |
|
687 | + if ('vat_rule' == $vars['orderby']) { |
|
688 | 688 | return array_merge( |
689 | 689 | $vars, |
690 | 690 | array( |
@@ -695,7 +695,7 @@ discard block |
||
695 | 695 | } |
696 | 696 | |
697 | 697 | // By price. |
698 | - if ( 'price' == $vars['orderby'] ) { |
|
698 | + if ('price' == $vars['orderby']) { |
|
699 | 699 | return array_merge( |
700 | 700 | $vars, |
701 | 701 | array( |
@@ -712,27 +712,27 @@ discard block |
||
712 | 712 | /** |
713 | 713 | * Fired when deleting a post. |
714 | 714 | */ |
715 | - public static function delete_post( $post_id ) { |
|
715 | + public static function delete_post($post_id) { |
|
716 | 716 | |
717 | - switch ( get_post_type( $post_id ) ) { |
|
717 | + switch (get_post_type($post_id)) { |
|
718 | 718 | |
719 | 719 | case 'wpi_item' : |
720 | - do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
720 | + do_action("getpaid_before_delete_item", new WPInv_Item($post_id)); |
|
721 | 721 | break; |
722 | 722 | |
723 | 723 | case 'wpi_payment_form' : |
724 | - do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
724 | + do_action("getpaid_before_delete_payment_form", new GetPaid_Payment_Form($post_id)); |
|
725 | 725 | break; |
726 | 726 | |
727 | 727 | case 'wpi_discount' : |
728 | - do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
728 | + do_action("getpaid_before_delete_discount", new WPInv_Discount($post_id)); |
|
729 | 729 | break; |
730 | 730 | |
731 | 731 | case 'wpi_invoice' : |
732 | - $invoice = new WPInv_Invoice( $post_id ); |
|
733 | - do_action( "getpaid_before_delete_invoice", $invoice ); |
|
734 | - $invoice->get_data_store()->delete_items( $invoice ); |
|
735 | - $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
732 | + $invoice = new WPInv_Invoice($post_id); |
|
733 | + do_action("getpaid_before_delete_invoice", $invoice); |
|
734 | + $invoice->get_data_store()->delete_items($invoice); |
|
735 | + $invoice->get_data_store()->delete_special_fields($invoice); |
|
736 | 736 | break; |
737 | 737 | } |
738 | 738 | } |
@@ -12,170 +12,170 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Checkout { |
14 | 14 | |
15 | - /** |
|
16 | - * @var GetPaid_Payment_Form_Submission |
|
17 | - */ |
|
18 | - protected $payment_form_submission; |
|
19 | - |
|
20 | - /** |
|
21 | - * Class constructor. |
|
22 | - * |
|
23 | - * @param GetPaid_Payment_Form_Submission $submission |
|
24 | - */ |
|
25 | - public function __construct( $submission ) { |
|
26 | - $this->payment_form_submission = $submission; |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Processes the checkout. |
|
31 | - * |
|
32 | - */ |
|
33 | - public function process_checkout() { |
|
34 | - |
|
35 | - // Validate the submission. |
|
36 | - $this->validate_submission(); |
|
37 | - |
|
38 | - // Prepare the invoice. |
|
39 | - $items = $this->get_submission_items(); |
|
40 | - $invoice = $this->get_submission_invoice(); |
|
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | - $prepared = $this->prepare_submission_data_for_saving( $invoice ); |
|
43 | - |
|
44 | - // Save the invoice. |
|
45 | - $invoice->recalculate_total(); |
|
15 | + /** |
|
16 | + * @var GetPaid_Payment_Form_Submission |
|
17 | + */ |
|
18 | + protected $payment_form_submission; |
|
19 | + |
|
20 | + /** |
|
21 | + * Class constructor. |
|
22 | + * |
|
23 | + * @param GetPaid_Payment_Form_Submission $submission |
|
24 | + */ |
|
25 | + public function __construct( $submission ) { |
|
26 | + $this->payment_form_submission = $submission; |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Processes the checkout. |
|
31 | + * |
|
32 | + */ |
|
33 | + public function process_checkout() { |
|
34 | + |
|
35 | + // Validate the submission. |
|
36 | + $this->validate_submission(); |
|
37 | + |
|
38 | + // Prepare the invoice. |
|
39 | + $items = $this->get_submission_items(); |
|
40 | + $invoice = $this->get_submission_invoice(); |
|
41 | + $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | + $prepared = $this->prepare_submission_data_for_saving( $invoice ); |
|
43 | + |
|
44 | + // Save the invoice. |
|
45 | + $invoice->recalculate_total(); |
|
46 | 46 | $invoice->save(); |
47 | 47 | |
48 | - // Send to the gateway. |
|
49 | - $this->post_process_submission( $invoice, $prepared ); |
|
50 | - } |
|
48 | + // Send to the gateway. |
|
49 | + $this->post_process_submission( $invoice, $prepared ); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Validates the submission. |
|
54 | - * |
|
55 | - */ |
|
56 | - protected function validate_submission() { |
|
52 | + /** |
|
53 | + * Validates the submission. |
|
54 | + * |
|
55 | + */ |
|
56 | + protected function validate_submission() { |
|
57 | 57 | |
58 | - $submission = $this->payment_form_submission; |
|
59 | - $data = $submission->get_data(); |
|
58 | + $submission = $this->payment_form_submission; |
|
59 | + $data = $submission->get_data(); |
|
60 | 60 | |
61 | - // Do we have an error? |
|
61 | + // Do we have an error? |
|
62 | 62 | if ( ! empty( $submission->last_error ) ) { |
63 | - wp_send_json_error( $submission->last_error ); |
|
63 | + wp_send_json_error( $submission->last_error ); |
|
64 | 64 | } |
65 | 65 | |
66 | - // We need a billing email. |
|
66 | + // We need a billing email. |
|
67 | 67 | if ( ! $submission->has_billing_email() ) { |
68 | 68 | wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
69 | - } |
|
69 | + } |
|
70 | 70 | |
71 | - // Non-recurring gateways should not be allowed to process recurring invoices. |
|
72 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
73 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
74 | - } |
|
71 | + // Non-recurring gateways should not be allowed to process recurring invoices. |
|
72 | + if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
73 | + wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
74 | + } |
|
75 | 75 | |
76 | - // Ensure the gateway is active. |
|
77 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
78 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
79 | - } |
|
76 | + // Ensure the gateway is active. |
|
77 | + if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
78 | + wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
79 | + } |
|
80 | 80 | |
81 | - // Clear any existing errors. |
|
82 | - wpinv_clear_errors(); |
|
81 | + // Clear any existing errors. |
|
82 | + wpinv_clear_errors(); |
|
83 | 83 | |
84 | - // Allow themes and plugins to hook to errors |
|
85 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
84 | + // Allow themes and plugins to hook to errors |
|
85 | + do_action( 'getpaid_checkout_error_checks', $submission ); |
|
86 | 86 | |
87 | - // Do we have any errors? |
|
87 | + // Do we have any errors? |
|
88 | 88 | if ( wpinv_get_errors() ) { |
89 | 89 | wp_send_json_error( getpaid_get_errors_html() ); |
90 | - } |
|
90 | + } |
|
91 | 91 | |
92 | - } |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Retrieves submission items. |
|
96 | - * |
|
97 | - * @return GetPaid_Form_Item[] |
|
98 | - */ |
|
99 | - protected function get_submission_items() { |
|
94 | + /** |
|
95 | + * Retrieves submission items. |
|
96 | + * |
|
97 | + * @return GetPaid_Form_Item[] |
|
98 | + */ |
|
99 | + protected function get_submission_items() { |
|
100 | 100 | |
101 | - $items = $this->payment_form_submission->get_items(); |
|
101 | + $items = $this->payment_form_submission->get_items(); |
|
102 | 102 | |
103 | 103 | // Ensure that we have items. |
104 | 104 | if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
105 | 105 | wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
106 | - } |
|
107 | - |
|
108 | - return $items; |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Retrieves submission invoice. |
|
113 | - * |
|
114 | - * @return WPInv_Invoice |
|
115 | - */ |
|
116 | - protected function get_submission_invoice() { |
|
117 | - $submission = $this->payment_form_submission; |
|
118 | - |
|
119 | - if ( ! $submission->has_invoice() ) { |
|
120 | - $invoice = new WPInv_Invoice(); |
|
121 | - $invoice->created_via( 'payment_form' ); |
|
122 | - return $invoice; |
|
123 | 106 | } |
124 | 107 | |
125 | - $invoice = $submission->get_invoice(); |
|
108 | + return $items; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Retrieves submission invoice. |
|
113 | + * |
|
114 | + * @return WPInv_Invoice |
|
115 | + */ |
|
116 | + protected function get_submission_invoice() { |
|
117 | + $submission = $this->payment_form_submission; |
|
126 | 118 | |
127 | - // Make sure that it is neither paid or refunded. |
|
128 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
129 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
130 | - } |
|
119 | + if ( ! $submission->has_invoice() ) { |
|
120 | + $invoice = new WPInv_Invoice(); |
|
121 | + $invoice->created_via( 'payment_form' ); |
|
122 | + return $invoice; |
|
123 | + } |
|
131 | 124 | |
132 | - return $invoice; |
|
133 | - } |
|
125 | + $invoice = $submission->get_invoice(); |
|
134 | 126 | |
135 | - /** |
|
136 | - * Processes the submission invoice. |
|
137 | - * |
|
138 | - * @param WPInv_Invoice $invoice |
|
139 | - * @param GetPaid_Form_Item[] $items |
|
140 | - * @return WPInv_Invoice |
|
141 | - */ |
|
142 | - protected function process_submission_invoice( $invoice, $items ) { |
|
127 | + // Make sure that it is neither paid or refunded. |
|
128 | + if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
129 | + wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
130 | + } |
|
143 | 131 | |
144 | - $submission = $this->payment_form_submission; |
|
145 | - $data = $submission->get_data(); |
|
132 | + return $invoice; |
|
133 | + } |
|
146 | 134 | |
147 | - // Set-up the invoice details. |
|
148 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
149 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
150 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
135 | + /** |
|
136 | + * Processes the submission invoice. |
|
137 | + * |
|
138 | + * @param WPInv_Invoice $invoice |
|
139 | + * @param GetPaid_Form_Item[] $items |
|
140 | + * @return WPInv_Invoice |
|
141 | + */ |
|
142 | + protected function process_submission_invoice( $invoice, $items ) { |
|
143 | + |
|
144 | + $submission = $this->payment_form_submission; |
|
145 | + $data = $submission->get_data(); |
|
146 | + |
|
147 | + // Set-up the invoice details. |
|
148 | + $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
149 | + $invoice->set_user_id( $this->get_submission_customer() ); |
|
150 | + $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
151 | 151 | $invoice->set_items( $items ); |
152 | 152 | $invoice->set_fees( $submission->get_fees() ); |
153 | 153 | $invoice->set_taxes( $submission->get_taxes() ); |
154 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
155 | - $invoice->set_gateway( $data['wpi-gateway'] ); |
|
154 | + $invoice->set_discounts( $submission->get_discounts() ); |
|
155 | + $invoice->set_gateway( $data['wpi-gateway'] ); |
|
156 | 156 | |
157 | - if ( $submission->has_discount_code() ) { |
|
157 | + if ( $submission->has_discount_code() ) { |
|
158 | 158 | $invoice->set_discount_code( $submission->get_discount_code() ); |
159 | - } |
|
160 | - |
|
161 | - getpaid_maybe_add_default_address( $invoice ); |
|
162 | - return $invoice; |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Retrieves the submission's customer. |
|
167 | - * |
|
168 | - * @return int The customer id. |
|
169 | - */ |
|
170 | - protected function get_submission_customer() { |
|
171 | - $submission = $this->payment_form_submission; |
|
172 | - |
|
173 | - // If this is an existing invoice... |
|
174 | - if ( $submission->has_invoice() ) { |
|
175 | - return $submission->get_invoice()->get_user_id(); |
|
176 | - } |
|
177 | - |
|
178 | - // (Maybe) create the user. |
|
159 | + } |
|
160 | + |
|
161 | + getpaid_maybe_add_default_address( $invoice ); |
|
162 | + return $invoice; |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Retrieves the submission's customer. |
|
167 | + * |
|
168 | + * @return int The customer id. |
|
169 | + */ |
|
170 | + protected function get_submission_customer() { |
|
171 | + $submission = $this->payment_form_submission; |
|
172 | + |
|
173 | + // If this is an existing invoice... |
|
174 | + if ( $submission->has_invoice() ) { |
|
175 | + return $submission->get_invoice()->get_user_id(); |
|
176 | + } |
|
177 | + |
|
178 | + // (Maybe) create the user. |
|
179 | 179 | $user = get_current_user_id(); |
180 | 180 | |
181 | 181 | if ( empty( $user ) ) { |
@@ -192,31 +192,31 @@ discard block |
||
192 | 192 | |
193 | 193 | if ( is_numeric( $user ) ) { |
194 | 194 | return $user; |
195 | - } |
|
195 | + } |
|
196 | 196 | |
197 | - return $user->ID; |
|
197 | + return $user->ID; |
|
198 | 198 | |
199 | - } |
|
199 | + } |
|
200 | 200 | |
201 | - /** |
|
201 | + /** |
|
202 | 202 | * Prepares submission data for saving to the database. |
203 | 203 | * |
204 | - * @param WPInv_Invoice $invoice |
|
204 | + * @param WPInv_Invoice $invoice |
|
205 | 205 | */ |
206 | 206 | public function prepare_submission_data_for_saving( &$invoice ) { |
207 | 207 | |
208 | - $submission = $this->payment_form_submission; |
|
208 | + $submission = $this->payment_form_submission; |
|
209 | 209 | |
210 | - // Prepared submission details. |
|
210 | + // Prepared submission details. |
|
211 | 211 | $prepared = array(); |
212 | 212 | |
213 | 213 | // Raw submission details. |
214 | - $data = $submission->get_data(); |
|
214 | + $data = $submission->get_data(); |
|
215 | 215 | |
216 | - // Loop throught the submitted details. |
|
216 | + // Loop throught the submitted details. |
|
217 | 217 | foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
218 | 218 | |
219 | - // Skip premade fields. |
|
219 | + // Skip premade fields. |
|
220 | 220 | if ( ! empty( $field['premade'] ) ) { |
221 | 221 | continue; |
222 | 222 | } |
@@ -259,21 +259,21 @@ discard block |
||
259 | 259 | $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] ); |
260 | 260 | } |
261 | 261 | |
262 | - } |
|
262 | + } |
|
263 | 263 | |
264 | - return $prepared; |
|
264 | + return $prepared; |
|
265 | 265 | |
266 | - } |
|
266 | + } |
|
267 | 267 | |
268 | - /** |
|
269 | - * Confirms the submission is valid and send users to the gateway. |
|
270 | - * |
|
271 | - * @param WPInv_Invoice $invoice |
|
272 | - * @param array $prepared_payment_form_data |
|
273 | - */ |
|
274 | - protected function post_process_submission( $invoice, $prepared_payment_form_data ) { |
|
268 | + /** |
|
269 | + * Confirms the submission is valid and send users to the gateway. |
|
270 | + * |
|
271 | + * @param WPInv_Invoice $invoice |
|
272 | + * @param array $prepared_payment_form_data |
|
273 | + */ |
|
274 | + protected function post_process_submission( $invoice, $prepared_payment_form_data ) { |
|
275 | 275 | |
276 | - // Ensure the invoice exists. |
|
276 | + // Ensure the invoice exists. |
|
277 | 277 | if ( ! $invoice->exists() ) { |
278 | 278 | wp_send_json_error( __( 'An error occured while saving your invoice.', 'invoicing' ) ); |
279 | 279 | } |
@@ -281,65 +281,65 @@ discard block |
||
281 | 281 | // Save payment form data. |
282 | 282 | if ( ! empty( $prepared_payment_form_data ) ) { |
283 | 283 | update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data ); |
284 | - } |
|
284 | + } |
|
285 | 285 | |
286 | - // Backwards compatibility. |
|
286 | + // Backwards compatibility. |
|
287 | 287 | add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
288 | 288 | |
289 | - $this->process_payment( $invoice ); |
|
289 | + $this->process_payment( $invoice ); |
|
290 | 290 | |
291 | 291 | // If we are here, there was an error. |
292 | - wpinv_send_back_to_checkout(); |
|
292 | + wpinv_send_back_to_checkout(); |
|
293 | 293 | |
294 | - } |
|
294 | + } |
|
295 | 295 | |
296 | - /** |
|
297 | - * Processes the actual payment. |
|
298 | - * |
|
299 | - * @param WPInv_Invoice $invoice |
|
300 | - */ |
|
301 | - protected function process_payment( $invoice ) { |
|
296 | + /** |
|
297 | + * Processes the actual payment. |
|
298 | + * |
|
299 | + * @param WPInv_Invoice $invoice |
|
300 | + */ |
|
301 | + protected function process_payment( $invoice ) { |
|
302 | 302 | |
303 | - $submission = $this->payment_form_submission; |
|
303 | + $submission = $this->payment_form_submission; |
|
304 | 304 | |
305 | - // No need to send free invoices to the gateway. |
|
306 | - if ( $invoice->is_free() ) { |
|
307 | - $invoice->set_gateway( 'none' ); |
|
308 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
309 | - $invoice->mark_paid(); |
|
310 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
311 | - } |
|
305 | + // No need to send free invoices to the gateway. |
|
306 | + if ( $invoice->is_free() ) { |
|
307 | + $invoice->set_gateway( 'none' ); |
|
308 | + $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
309 | + $invoice->mark_paid(); |
|
310 | + wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
311 | + } |
|
312 | 312 | |
313 | - // Clear any checkout errors. |
|
314 | - wpinv_clear_errors(); |
|
313 | + // Clear any checkout errors. |
|
314 | + wpinv_clear_errors(); |
|
315 | 315 | |
316 | - // Fires before sending to the gateway. |
|
317 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
316 | + // Fires before sending to the gateway. |
|
317 | + do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
318 | 318 | |
319 | - // Allow the sumission data to be modified before it is sent to the gateway. |
|
320 | - $submission_data = $submission->get_data(); |
|
321 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
322 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
319 | + // Allow the sumission data to be modified before it is sent to the gateway. |
|
320 | + $submission_data = $submission->get_data(); |
|
321 | + $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
322 | + $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
323 | 323 | |
324 | - // Validate the currency. |
|
325 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
326 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) ); |
|
327 | - } |
|
324 | + // Validate the currency. |
|
325 | + if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
326 | + wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) ); |
|
327 | + } |
|
328 | 328 | |
329 | - // Check to see if we have any errors. |
|
330 | - if ( wpinv_get_errors() ) { |
|
331 | - wpinv_send_back_to_checkout(); |
|
332 | - } |
|
329 | + // Check to see if we have any errors. |
|
330 | + if ( wpinv_get_errors() ) { |
|
331 | + wpinv_send_back_to_checkout(); |
|
332 | + } |
|
333 | 333 | |
334 | - // Send info to the gateway for payment processing |
|
335 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
334 | + // Send info to the gateway for payment processing |
|
335 | + do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
336 | 336 | |
337 | - // Backwards compatibility. |
|
338 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
337 | + // Backwards compatibility. |
|
338 | + wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
339 | 339 | |
340 | - } |
|
340 | + } |
|
341 | 341 | |
342 | - /** |
|
342 | + /** |
|
343 | 343 | * Sends a redrect response to payment details. |
344 | 344 | * |
345 | 345 | */ |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Main Checkout Class. |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @param GetPaid_Payment_Form_Submission $submission |
24 | 24 | */ |
25 | - public function __construct( $submission ) { |
|
25 | + public function __construct($submission) { |
|
26 | 26 | $this->payment_form_submission = $submission; |
27 | 27 | } |
28 | 28 | |
@@ -38,15 +38,15 @@ discard block |
||
38 | 38 | // Prepare the invoice. |
39 | 39 | $items = $this->get_submission_items(); |
40 | 40 | $invoice = $this->get_submission_invoice(); |
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | - $prepared = $this->prepare_submission_data_for_saving( $invoice ); |
|
41 | + $invoice = $this->process_submission_invoice($invoice, $items); |
|
42 | + $prepared = $this->prepare_submission_data_for_saving($invoice); |
|
43 | 43 | |
44 | 44 | // Save the invoice. |
45 | 45 | $invoice->recalculate_total(); |
46 | 46 | $invoice->save(); |
47 | 47 | |
48 | 48 | // Send to the gateway. |
49 | - $this->post_process_submission( $invoice, $prepared ); |
|
49 | + $this->post_process_submission($invoice, $prepared); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -59,34 +59,34 @@ discard block |
||
59 | 59 | $data = $submission->get_data(); |
60 | 60 | |
61 | 61 | // Do we have an error? |
62 | - if ( ! empty( $submission->last_error ) ) { |
|
63 | - wp_send_json_error( $submission->last_error ); |
|
62 | + if (!empty($submission->last_error)) { |
|
63 | + wp_send_json_error($submission->last_error); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | // We need a billing email. |
67 | - if ( ! $submission->has_billing_email() ) { |
|
68 | - wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
|
67 | + if (!$submission->has_billing_email()) { |
|
68 | + wp_send_json_error(__('Provide a valid billing email.', 'invoicing')); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | // Non-recurring gateways should not be allowed to process recurring invoices. |
72 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
73 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
72 | + if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) { |
|
73 | + wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing')); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | // Ensure the gateway is active. |
77 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
78 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
77 | + if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) { |
|
78 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway is not active', 'invoicing')); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | // Clear any existing errors. |
82 | 82 | wpinv_clear_errors(); |
83 | 83 | |
84 | 84 | // Allow themes and plugins to hook to errors |
85 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
85 | + do_action('getpaid_checkout_error_checks', $submission); |
|
86 | 86 | |
87 | 87 | // Do we have any errors? |
88 | - if ( wpinv_get_errors() ) { |
|
89 | - wp_send_json_error( getpaid_get_errors_html() ); |
|
88 | + if (wpinv_get_errors()) { |
|
89 | + wp_send_json_error(getpaid_get_errors_html()); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | } |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | $items = $this->payment_form_submission->get_items(); |
102 | 102 | |
103 | 103 | // Ensure that we have items. |
104 | - if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
|
105 | - wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
|
104 | + if (empty($items) && !$this->payment_form_submission->has_fees()) { |
|
105 | + wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing')); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | return $items; |
@@ -116,17 +116,17 @@ discard block |
||
116 | 116 | protected function get_submission_invoice() { |
117 | 117 | $submission = $this->payment_form_submission; |
118 | 118 | |
119 | - if ( ! $submission->has_invoice() ) { |
|
119 | + if (!$submission->has_invoice()) { |
|
120 | 120 | $invoice = new WPInv_Invoice(); |
121 | - $invoice->created_via( 'payment_form' ); |
|
121 | + $invoice->created_via('payment_form'); |
|
122 | 122 | return $invoice; |
123 | 123 | } |
124 | 124 | |
125 | 125 | $invoice = $submission->get_invoice(); |
126 | 126 | |
127 | 127 | // Make sure that it is neither paid or refunded. |
128 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
129 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
128 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
129 | + wp_send_json_error(__('This invoice has already been paid for.', 'invoicing')); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | return $invoice; |
@@ -139,26 +139,26 @@ discard block |
||
139 | 139 | * @param GetPaid_Form_Item[] $items |
140 | 140 | * @return WPInv_Invoice |
141 | 141 | */ |
142 | - protected function process_submission_invoice( $invoice, $items ) { |
|
142 | + protected function process_submission_invoice($invoice, $items) { |
|
143 | 143 | |
144 | 144 | $submission = $this->payment_form_submission; |
145 | 145 | $data = $submission->get_data(); |
146 | 146 | |
147 | 147 | // Set-up the invoice details. |
148 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
149 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
150 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
151 | - $invoice->set_items( $items ); |
|
152 | - $invoice->set_fees( $submission->get_fees() ); |
|
153 | - $invoice->set_taxes( $submission->get_taxes() ); |
|
154 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
155 | - $invoice->set_gateway( $data['wpi-gateway'] ); |
|
156 | - |
|
157 | - if ( $submission->has_discount_code() ) { |
|
158 | - $invoice->set_discount_code( $submission->get_discount_code() ); |
|
148 | + $invoice->set_email(sanitize_email($submission->get_billing_email())); |
|
149 | + $invoice->set_user_id($this->get_submission_customer()); |
|
150 | + $invoice->set_payment_form(absint($submission->get_payment_form()->get_id())); |
|
151 | + $invoice->set_items($items); |
|
152 | + $invoice->set_fees($submission->get_fees()); |
|
153 | + $invoice->set_taxes($submission->get_taxes()); |
|
154 | + $invoice->set_discounts($submission->get_discounts()); |
|
155 | + $invoice->set_gateway($data['wpi-gateway']); |
|
156 | + |
|
157 | + if ($submission->has_discount_code()) { |
|
158 | + $invoice->set_discount_code($submission->get_discount_code()); |
|
159 | 159 | } |
160 | 160 | |
161 | - getpaid_maybe_add_default_address( $invoice ); |
|
161 | + getpaid_maybe_add_default_address($invoice); |
|
162 | 162 | return $invoice; |
163 | 163 | } |
164 | 164 | |
@@ -171,26 +171,26 @@ discard block |
||
171 | 171 | $submission = $this->payment_form_submission; |
172 | 172 | |
173 | 173 | // If this is an existing invoice... |
174 | - if ( $submission->has_invoice() ) { |
|
174 | + if ($submission->has_invoice()) { |
|
175 | 175 | return $submission->get_invoice()->get_user_id(); |
176 | 176 | } |
177 | 177 | |
178 | 178 | // (Maybe) create the user. |
179 | 179 | $user = get_current_user_id(); |
180 | 180 | |
181 | - if ( empty( $user ) ) { |
|
182 | - $user = get_user_by( 'email', $submission->get_billing_email() ); |
|
181 | + if (empty($user)) { |
|
182 | + $user = get_user_by('email', $submission->get_billing_email()); |
|
183 | 183 | } |
184 | 184 | |
185 | - if ( empty( $user ) ) { |
|
186 | - $user = wpinv_create_user( $submission->get_billing_email() ); |
|
185 | + if (empty($user)) { |
|
186 | + $user = wpinv_create_user($submission->get_billing_email()); |
|
187 | 187 | } |
188 | 188 | |
189 | - if ( is_wp_error( $user ) ) { |
|
190 | - wp_send_json_error( $user->get_error_message() ); |
|
189 | + if (is_wp_error($user)) { |
|
190 | + wp_send_json_error($user->get_error_message()); |
|
191 | 191 | } |
192 | 192 | |
193 | - if ( is_numeric( $user ) ) { |
|
193 | + if (is_numeric($user)) { |
|
194 | 194 | return $user; |
195 | 195 | } |
196 | 196 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * |
204 | 204 | * @param WPInv_Invoice $invoice |
205 | 205 | */ |
206 | - public function prepare_submission_data_for_saving( &$invoice ) { |
|
206 | + public function prepare_submission_data_for_saving(&$invoice) { |
|
207 | 207 | |
208 | 208 | $submission = $this->payment_form_submission; |
209 | 209 | |
@@ -214,49 +214,49 @@ discard block |
||
214 | 214 | $data = $submission->get_data(); |
215 | 215 | |
216 | 216 | // Loop throught the submitted details. |
217 | - foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
|
217 | + foreach ($submission->get_payment_form()->get_elements() as $field) { |
|
218 | 218 | |
219 | 219 | // Skip premade fields. |
220 | - if ( ! empty( $field['premade'] ) ) { |
|
220 | + if (!empty($field['premade'])) { |
|
221 | 221 | continue; |
222 | 222 | } |
223 | 223 | |
224 | 224 | // If it is required and not set, abort. |
225 | - if ( ! $submission->is_required_field_set( $field ) ) { |
|
226 | - wp_send_json_error( __( 'Some required fields are not set.', 'invoicing' ) ); |
|
225 | + if (!$submission->is_required_field_set($field)) { |
|
226 | + wp_send_json_error(__('Some required fields are not set.', 'invoicing')); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | // Handle address fields. |
230 | - if ( $field['type'] == 'address' ) { |
|
230 | + if ($field['type'] == 'address') { |
|
231 | 231 | |
232 | - foreach ( $field['fields'] as $address_field ) { |
|
232 | + foreach ($field['fields'] as $address_field) { |
|
233 | 233 | |
234 | 234 | // skip if it is not visible. |
235 | - if ( empty( $address_field['visible'] ) ) { |
|
235 | + if (empty($address_field['visible'])) { |
|
236 | 236 | continue; |
237 | 237 | } |
238 | 238 | |
239 | 239 | // If it is required and not set, abort |
240 | - if ( ! empty( $address_field['required'] ) && empty( $data[ $address_field['name'] ] ) ) { |
|
241 | - wp_send_json_error( __( 'Some required fields are not set.', 'invoicing' ) ); |
|
240 | + if (!empty($address_field['required']) && empty($data[$address_field['name']])) { |
|
241 | + wp_send_json_error(__('Some required fields are not set.', 'invoicing')); |
|
242 | 242 | } |
243 | 243 | |
244 | - if ( isset( $data[ $address_field['name'] ] ) ) { |
|
245 | - $name = str_replace( 'wpinv_', '', $address_field['name'] ); |
|
244 | + if (isset($data[$address_field['name']])) { |
|
245 | + $name = str_replace('wpinv_', '', $address_field['name']); |
|
246 | 246 | $method = "set_$name"; |
247 | - $invoice->$method( wpinv_clean( $data[ $address_field['name'] ] ) ); |
|
247 | + $invoice->$method(wpinv_clean($data[$address_field['name']])); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | } |
251 | 251 | |
252 | - } else if ( isset( $data[ $field['id'] ] ) ) { |
|
252 | + } else if (isset($data[$field['id']])) { |
|
253 | 253 | $label = $field['id']; |
254 | 254 | |
255 | - if ( isset( $field['label'] ) ) { |
|
255 | + if (isset($field['label'])) { |
|
256 | 256 | $label = $field['label']; |
257 | 257 | } |
258 | 258 | |
259 | - $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] ); |
|
259 | + $prepared[wpinv_clean($label)] = wpinv_clean($data[$field['id']]); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | } |
@@ -271,22 +271,22 @@ discard block |
||
271 | 271 | * @param WPInv_Invoice $invoice |
272 | 272 | * @param array $prepared_payment_form_data |
273 | 273 | */ |
274 | - protected function post_process_submission( $invoice, $prepared_payment_form_data ) { |
|
274 | + protected function post_process_submission($invoice, $prepared_payment_form_data) { |
|
275 | 275 | |
276 | 276 | // Ensure the invoice exists. |
277 | - if ( ! $invoice->exists() ) { |
|
278 | - wp_send_json_error( __( 'An error occured while saving your invoice.', 'invoicing' ) ); |
|
277 | + if (!$invoice->exists()) { |
|
278 | + wp_send_json_error(__('An error occured while saving your invoice.', 'invoicing')); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | // Save payment form data. |
282 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
283 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data ); |
|
282 | + if (!empty($prepared_payment_form_data)) { |
|
283 | + update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | // Backwards compatibility. |
287 | - add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
|
287 | + add_filter('wp_redirect', array($this, 'send_redirect_response')); |
|
288 | 288 | |
289 | - $this->process_payment( $invoice ); |
|
289 | + $this->process_payment($invoice); |
|
290 | 290 | |
291 | 291 | // If we are here, there was an error. |
292 | 292 | wpinv_send_back_to_checkout(); |
@@ -298,44 +298,44 @@ discard block |
||
298 | 298 | * |
299 | 299 | * @param WPInv_Invoice $invoice |
300 | 300 | */ |
301 | - protected function process_payment( $invoice ) { |
|
301 | + protected function process_payment($invoice) { |
|
302 | 302 | |
303 | 303 | $submission = $this->payment_form_submission; |
304 | 304 | |
305 | 305 | // No need to send free invoices to the gateway. |
306 | - if ( $invoice->is_free() ) { |
|
307 | - $invoice->set_gateway( 'none' ); |
|
308 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
306 | + if ($invoice->is_free()) { |
|
307 | + $invoice->set_gateway('none'); |
|
308 | + $invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true); |
|
309 | 309 | $invoice->mark_paid(); |
310 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
310 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | // Clear any checkout errors. |
314 | 314 | wpinv_clear_errors(); |
315 | 315 | |
316 | 316 | // Fires before sending to the gateway. |
317 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
317 | + do_action('getpaid_checkout_before_gateway', $invoice, $submission); |
|
318 | 318 | |
319 | 319 | // Allow the sumission data to be modified before it is sent to the gateway. |
320 | 320 | $submission_data = $submission->get_data(); |
321 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
322 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
321 | + $submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice); |
|
322 | + $submission_data = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice); |
|
323 | 323 | |
324 | 324 | // Validate the currency. |
325 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
326 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) ); |
|
325 | + if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) { |
|
326 | + wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support the invoice currency', 'invoicing')); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | // Check to see if we have any errors. |
330 | - if ( wpinv_get_errors() ) { |
|
330 | + if (wpinv_get_errors()) { |
|
331 | 331 | wpinv_send_back_to_checkout(); |
332 | 332 | } |
333 | 333 | |
334 | 334 | // Send info to the gateway for payment processing |
335 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
335 | + do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission); |
|
336 | 336 | |
337 | 337 | // Backwards compatibility. |
338 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
338 | + wpinv_send_to_gateway($submission_gateway, $invoice); |
|
339 | 339 | |
340 | 340 | } |
341 | 341 | |
@@ -343,9 +343,9 @@ discard block |
||
343 | 343 | * Sends a redrect response to payment details. |
344 | 344 | * |
345 | 345 | */ |
346 | - public function send_redirect_response( $url ) { |
|
347 | - $url = urlencode( $url ); |
|
348 | - wp_send_json_success( $url ); |
|
346 | + public function send_redirect_response($url) { |
|
347 | + $url = urlencode($url); |
|
348 | + wp_send_json_success($url); |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,187 +10,187 @@ discard block |
||
10 | 10 | class GetPaid_Payment_Form_Submission { |
11 | 11 | |
12 | 12 | /** |
13 | - * Submission ID |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - public $id = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * The raw submission data. |
|
21 | - * |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $data = null; |
|
25 | - |
|
26 | - /** |
|
27 | - * Submission totals |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $totals = array( |
|
32 | - |
|
33 | - 'subtotal' => array( |
|
34 | - 'initial' => 0, |
|
35 | - 'recurring' => 0, |
|
36 | - ), |
|
37 | - |
|
38 | - 'discount' => array( |
|
39 | - 'initial' => 0, |
|
40 | - 'recurring' => 0, |
|
41 | - ), |
|
42 | - |
|
43 | - 'fees' => array( |
|
44 | - 'initial' => 0, |
|
45 | - 'recurring' => 0, |
|
46 | - ), |
|
47 | - |
|
48 | - 'taxes' => array( |
|
49 | - 'initial' => 0, |
|
50 | - 'recurring' => 0, |
|
51 | - ), |
|
52 | - |
|
53 | - ); |
|
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 ) && is_email( $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 ) && is_email( $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 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | $this->state = wpinv_get_default_state(); |
135 | 135 | |
136 | 136 | // Do we have an actual submission? |
137 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
138 | - $this->load_data( $_POST ); |
|
137 | + if (isset($_POST['getpaid_payment_form_submission'])) { |
|
138 | + $this->load_data($_POST); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | } |
@@ -145,19 +145,19 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @param array $data |
147 | 147 | */ |
148 | - public function load_data( $data ) { |
|
148 | + public function load_data($data) { |
|
149 | 149 | |
150 | 150 | // Remove slashes from the submitted data... |
151 | - $data = wp_unslash( $data ); |
|
151 | + $data = wp_unslash($data); |
|
152 | 152 | |
153 | 153 | // Allow plugins to filter the data. |
154 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
154 | + $data = apply_filters('getpaid_submission_data', $data, $this); |
|
155 | 155 | |
156 | 156 | // Cache it... |
157 | 157 | $this->data = $data; |
158 | 158 | |
159 | 159 | // Then generate a unique id from the data. |
160 | - $this->id = md5( wp_json_encode( $data ) ); |
|
160 | + $this->id = md5(wp_json_encode($data)); |
|
161 | 161 | |
162 | 162 | // Finally, process the submission. |
163 | 163 | try { |
@@ -167,26 +167,26 @@ discard block |
||
167 | 167 | $processors = apply_filters( |
168 | 168 | 'getpaid_payment_form_submission_processors', |
169 | 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' ), |
|
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 | 176 | ), |
177 | 177 | $this |
178 | 178 | ); |
179 | 179 | |
180 | - foreach ( $processors as $processor ) { |
|
181 | - call_user_func_array( $processor, array( &$this ) ); |
|
180 | + foreach ($processors as $processor) { |
|
181 | + call_user_func_array($processor, array(&$this)); |
|
182 | 182 | } |
183 | 183 | |
184 | - } catch ( Exception $e ) { |
|
184 | + } catch (Exception $e) { |
|
185 | 185 | $this->last_error = $e->getMessage(); |
186 | 186 | } |
187 | 187 | |
188 | 188 | // Fired when we are done processing a submission. |
189 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
189 | + do_action_ref_array('getpaid_process_submission', array(&$this)); |
|
190 | 190 | |
191 | 191 | } |
192 | 192 | |
@@ -207,18 +207,18 @@ discard block |
||
207 | 207 | public function process_payment_form() { |
208 | 208 | |
209 | 209 | // Every submission needs an active payment form. |
210 | - if ( empty( $this->data['form_id'] ) ) { |
|
211 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
210 | + if (empty($this->data['form_id'])) { |
|
211 | + throw new Exception(__('Missing payment form', 'invoicing')); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | // Fetch the payment form. |
215 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
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' ) ); |
|
217 | + if (!$this->payment_form->is_active()) { |
|
218 | + throw new Exception(__('Payment form not active', 'invoicing')); |
|
219 | 219 | } |
220 | 220 | |
221 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
221 | + do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this)); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -248,30 +248,30 @@ discard block |
||
248 | 248 | public function process_invoice() { |
249 | 249 | |
250 | 250 | // Abort if there is no invoice. |
251 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
251 | + if (empty($this->data['invoice_id'])) { |
|
252 | 252 | return; |
253 | 253 | } |
254 | 254 | |
255 | 255 | // If the submission is for an existing invoice, ensure that it exists |
256 | 256 | // and that it is not paid for. |
257 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
257 | + $invoice = wpinv_get_invoice($this->data['invoice_id']); |
|
258 | 258 | |
259 | - if ( empty( $invoice ) ) { |
|
260 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
259 | + if (empty($invoice)) { |
|
260 | + throw new Exception(__('Invalid invoice', 'invoicing')); |
|
261 | 261 | } |
262 | 262 | |
263 | - if ( $invoice->is_paid() ) { |
|
264 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
263 | + if ($invoice->is_paid()) { |
|
264 | + throw new Exception(__('This invoice is already paid for.', 'invoicing')); |
|
265 | 265 | } |
266 | 266 | |
267 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
267 | + $this->payment_form->set_items($invoice->get_items()); |
|
268 | 268 | $this->payment_form->invoice = $invoice; |
269 | 269 | |
270 | 270 | $this->country = $invoice->get_country(); |
271 | 271 | $this->state = $invoice->get_state(); |
272 | 272 | $this->invoice = $invoice; |
273 | 273 | |
274 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
274 | + do_action_ref_array('getpaid_submissions_process_invoice', array(&$this)); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | * @return bool |
292 | 292 | */ |
293 | 293 | public function has_invoice() { |
294 | - return ! empty( $this->invoice ); |
|
294 | + return !empty($this->invoice); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /* |
@@ -310,13 +310,13 @@ discard block |
||
310 | 310 | */ |
311 | 311 | public function process_items() { |
312 | 312 | |
313 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
313 | + $processor = new GetPaid_Payment_Form_Submission_Items($this); |
|
314 | 314 | |
315 | - foreach ( $processor->items as $item ) { |
|
316 | - $this->add_item( $item ); |
|
315 | + foreach ($processor->items as $item) { |
|
316 | + $this->add_item($item); |
|
317 | 317 | } |
318 | 318 | |
319 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
319 | + do_action_ref_array('getpaid_submissions_process_items', array(&$this)); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | /** |
@@ -325,18 +325,18 @@ discard block |
||
325 | 325 | * @since 1.0.19 |
326 | 326 | * @param GetPaid_Form_Item $item |
327 | 327 | */ |
328 | - public function add_item( $item ) { |
|
328 | + public function add_item($item) { |
|
329 | 329 | |
330 | 330 | // Make sure that it is available for purchase. |
331 | - if ( ! $item->can_purchase() ) { |
|
331 | + if (!$item->can_purchase()) { |
|
332 | 332 | return; |
333 | 333 | } |
334 | 334 | |
335 | 335 | // Each submission can only contain one recurring item. |
336 | - if ( $item->is_recurring() ) { |
|
336 | + if ($item->is_recurring()) { |
|
337 | 337 | |
338 | - if ( $this->has_recurring != 0 ) { |
|
339 | - throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) ); |
|
338 | + if ($this->has_recurring != 0) { |
|
339 | + throw new Exception(__('You can only buy one recurring item at a time.', 'invoicing')); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | $this->has_recurring = $item->get_id(); |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | } |
345 | 345 | |
346 | 346 | // Update the items and totals. |
347 | - $this->items[ $item->get_id() ] = $item; |
|
347 | + $this->items[$item->get_id()] = $item; |
|
348 | 348 | $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
349 | 349 | $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
350 | 350 | |
@@ -358,17 +358,17 @@ discard block |
||
358 | 358 | * |
359 | 359 | * @since 1.0.19 |
360 | 360 | */ |
361 | - public function remove_item( $item_id ) { |
|
361 | + public function remove_item($item_id) { |
|
362 | 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(); |
|
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 | 366 | |
367 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
367 | + if ($this->items[$item_id]->is_recurring()) { |
|
368 | 368 | $this->has_recurring = 0; |
369 | 369 | } |
370 | 370 | |
371 | - unset( $this->items[ $item_id ] ); |
|
371 | + unset($this->items[$item_id]); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | } |
@@ -418,26 +418,26 @@ discard block |
||
418 | 418 | public function process_taxes() { |
419 | 419 | |
420 | 420 | // Abort if we're not using taxes. |
421 | - if ( ! $this->use_taxes() ) { |
|
421 | + if (!$this->use_taxes()) { |
|
422 | 422 | return; |
423 | 423 | } |
424 | 424 | |
425 | 425 | // If a custom country && state has been passed in, use it to calculate taxes. |
426 | - if ( ! empty( $this->data['wpinv_country'] ) ) { |
|
426 | + if (!empty($this->data['wpinv_country'])) { |
|
427 | 427 | $this->country = $this->data['wpinv_country']; |
428 | 428 | } |
429 | 429 | |
430 | - if ( ! empty( $this->data['wpinv_state'] ) ) { |
|
430 | + if (!empty($this->data['wpinv_state'])) { |
|
431 | 431 | $this->country = $this->data['wpinv_state']; |
432 | 432 | } |
433 | 433 | |
434 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
434 | + $processor = new GetPaid_Payment_Form_Submission_Taxes($this); |
|
435 | 435 | |
436 | - foreach ( $processor->taxes as $tax ) { |
|
437 | - $this->add_tax( $tax ); |
|
436 | + foreach ($processor->taxes as $tax) { |
|
437 | + $this->add_tax($tax); |
|
438 | 438 | } |
439 | 439 | |
440 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
440 | + do_action_ref_array('getpaid_submissions_process_taxes', array(&$this)); |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | /** |
@@ -446,10 +446,10 @@ discard block |
||
446 | 446 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
447 | 447 | * @since 1.0.19 |
448 | 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'] ); |
|
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 | 453 | } |
454 | 454 | |
455 | 455 | /** |
@@ -457,12 +457,12 @@ discard block |
||
457 | 457 | * |
458 | 458 | * @since 1.0.19 |
459 | 459 | */ |
460 | - public function remove_tax( $tax_name ) { |
|
460 | + public function remove_tax($tax_name) { |
|
461 | 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 ] ); |
|
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 | 466 | } |
467 | 467 | |
468 | 468 | } |
@@ -476,11 +476,11 @@ discard block |
||
476 | 476 | |
477 | 477 | $use_taxes = wpinv_use_taxes(); |
478 | 478 | |
479 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
479 | + if ($this->has_invoice() && !$this->invoice->is_taxable()) { |
|
480 | 480 | $use_taxes = false; |
481 | 481 | } |
482 | 482 | |
483 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
483 | + return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this); |
|
484 | 484 | |
485 | 485 | } |
486 | 486 | |
@@ -529,13 +529,13 @@ discard block |
||
529 | 529 | |
530 | 530 | $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
531 | 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 ); |
|
532 | + $processor = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total); |
|
533 | 533 | |
534 | - foreach ( $processor->discounts as $discount ) { |
|
535 | - $this->add_discount( $discount ); |
|
534 | + foreach ($processor->discounts as $discount) { |
|
535 | + $this->add_discount($discount); |
|
536 | 536 | } |
537 | 537 | |
538 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
538 | + do_action_ref_array('getpaid_submissions_process_discounts', array(&$this)); |
|
539 | 539 | } |
540 | 540 | |
541 | 541 | /** |
@@ -544,10 +544,10 @@ discard block |
||
544 | 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 | 545 | * @since 1.0.19 |
546 | 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'] ); |
|
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 | 551 | } |
552 | 552 | |
553 | 553 | /** |
@@ -555,12 +555,12 @@ discard block |
||
555 | 555 | * |
556 | 556 | * @since 1.0.19 |
557 | 557 | */ |
558 | - public function remove_discount( $name ) { |
|
558 | + public function remove_discount($name) { |
|
559 | 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 ] ); |
|
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 | 564 | } |
565 | 565 | |
566 | 566 | } |
@@ -572,7 +572,7 @@ discard block |
||
572 | 572 | * @return bool |
573 | 573 | */ |
574 | 574 | public function has_discount_code() { |
575 | - return ! empty( $this->discounts['discount_code'] ); |
|
575 | + return !empty($this->discounts['discount_code']); |
|
576 | 576 | } |
577 | 577 | |
578 | 578 | /** |
@@ -629,13 +629,13 @@ discard block |
||
629 | 629 | */ |
630 | 630 | public function process_fees() { |
631 | 631 | |
632 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
632 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees($this); |
|
633 | 633 | |
634 | - foreach ( $fees_processor->fees as $fee ) { |
|
635 | - $this->add_fee( $fee ); |
|
634 | + foreach ($fees_processor->fees as $fee) { |
|
635 | + $this->add_fee($fee); |
|
636 | 636 | } |
637 | 637 | |
638 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
638 | + do_action_ref_array('getpaid_submissions_process_fees', array(&$this)); |
|
639 | 639 | } |
640 | 640 | |
641 | 641 | /** |
@@ -644,11 +644,11 @@ discard block |
||
644 | 644 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
645 | 645 | * @since 1.0.19 |
646 | 646 | */ |
647 | - public function add_fee( $fee ) { |
|
647 | + public function add_fee($fee) { |
|
648 | 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'] ); |
|
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 | 652 | |
653 | 653 | } |
654 | 654 | |
@@ -657,12 +657,12 @@ discard block |
||
657 | 657 | * |
658 | 658 | * @since 1.0.19 |
659 | 659 | */ |
660 | - public function remove_fee( $name ) { |
|
660 | + public function remove_fee($name) { |
|
661 | 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 ] ); |
|
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 | 666 | } |
667 | 667 | |
668 | 668 | } |
@@ -701,7 +701,7 @@ discard block |
||
701 | 701 | * @since 1.0.19 |
702 | 702 | */ |
703 | 703 | public function has_fees() { |
704 | - return count( $this->fees ) !== 0; |
|
704 | + return count($this->fees) !== 0; |
|
705 | 705 | } |
706 | 706 | |
707 | 707 | /* |
@@ -719,7 +719,7 @@ discard block |
||
719 | 719 | */ |
720 | 720 | public function get_total() { |
721 | 721 | $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
722 | - return max( $total, 0 ); |
|
722 | + return max($total, 0); |
|
723 | 723 | } |
724 | 724 | |
725 | 725 | /** |
@@ -729,7 +729,7 @@ discard block |
||
729 | 729 | */ |
730 | 730 | public function get_recurring_total() { |
731 | 731 | $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
732 | - return max( $total, 0 ); |
|
732 | + return max($total, 0); |
|
733 | 733 | } |
734 | 734 | |
735 | 735 | /** |
@@ -741,12 +741,12 @@ discard block |
||
741 | 741 | $initial = $this->get_total(); |
742 | 742 | $recurring = $this->get_recurring_total(); |
743 | 743 | |
744 | - if ( $this->has_recurring == 0 ) { |
|
744 | + if ($this->has_recurring == 0) { |
|
745 | 745 | $recurring = 0; |
746 | 746 | } |
747 | 747 | |
748 | 748 | $collect = $initial > 0 || $recurring > 0; |
749 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
749 | + return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this); |
|
750 | 750 | } |
751 | 751 | |
752 | 752 | /** |
@@ -755,7 +755,7 @@ discard block |
||
755 | 755 | * @since 1.0.19 |
756 | 756 | */ |
757 | 757 | public function get_billing_email() { |
758 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
758 | + return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this); |
|
759 | 759 | } |
760 | 760 | |
761 | 761 | /** |
@@ -765,7 +765,7 @@ discard block |
||
765 | 765 | */ |
766 | 766 | public function has_billing_email() { |
767 | 767 | $billing_email = $this->get_billing_email(); |
768 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
768 | + return !empty($billing_email) && is_email($billing_email); |
|
769 | 769 | } |
770 | 770 | |
771 | 771 | /** |
@@ -795,8 +795,8 @@ discard block |
||
795 | 795 | * @since 1.0.19 |
796 | 796 | * @return mixed |
797 | 797 | */ |
798 | - public function get_field( $field ) { |
|
799 | - return isset( $this->data[ $field ] ) ? $this->data[ $field ] : ''; |
|
798 | + public function get_field($field) { |
|
799 | + return isset($this->data[$field]) ? $this->data[$field] : ''; |
|
800 | 800 | } |
801 | 801 | |
802 | 802 | /** |
@@ -804,8 +804,8 @@ discard block |
||
804 | 804 | * |
805 | 805 | * @since 1.0.19 |
806 | 806 | */ |
807 | - public function is_required_field_set( $field ) { |
|
808 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
807 | + public function is_required_field_set($field) { |
|
808 | + return empty($field['required']) || !empty($this->data[$field['id']]); |
|
809 | 809 | } |
810 | 810 | |
811 | 811 | /** |
@@ -813,8 +813,8 @@ discard block |
||
813 | 813 | * |
814 | 814 | * @since 1.0.19 |
815 | 815 | */ |
816 | - public function format_amount( $amount ) { |
|
817 | - return wpinv_price( $amount, $this->get_currency() ); |
|
816 | + public function format_amount($amount) { |
|
817 | + return wpinv_price($amount, $this->get_currency()); |
|
818 | 818 | } |
819 | 819 | |
820 | 820 | } |
@@ -12,93 +12,93 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Daily_Maintenance { |
14 | 14 | |
15 | - /** |
|
16 | - * Class constructor. |
|
17 | - */ |
|
18 | - public function __construct(){ |
|
19 | - |
|
20 | - // Clear deprecated events. |
|
21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | - |
|
23 | - // (Maybe) schedule a cron that runs daily. |
|
24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | - |
|
26 | - // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | - |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * Schedules a cron to run every day at 7 a.m |
|
35 | - * |
|
36 | - */ |
|
37 | - public function maybe_create_scheduled_event() { |
|
38 | - |
|
39 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
40 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
41 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
42 | - } |
|
43 | - |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Clears deprecated events. |
|
48 | - * |
|
49 | - */ |
|
50 | - public function maybe_clear_deprecated_events() { |
|
51 | - |
|
52 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
53 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
54 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
55 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
56 | - } |
|
57 | - |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Fires the old hook for backwards compatibility. |
|
62 | - * |
|
63 | - */ |
|
64 | - public function backwards_compat() { |
|
65 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Expires expired subscriptions. |
|
70 | - * |
|
71 | - */ |
|
72 | - public function maybe_expire_subscriptions() { |
|
73 | - |
|
74 | - // Fetch expired subscriptions (skips those that expire today). |
|
75 | - $args = array( |
|
76 | - 'number' => -1, |
|
77 | - 'count_total' => false, |
|
78 | - 'status' => 'trialling active failing cancelled', |
|
79 | - 'date_expires_query' => array( |
|
80 | - 'before' => 'today', |
|
81 | - 'inclusive' => false, |
|
82 | - ), |
|
83 | - ); |
|
84 | - |
|
85 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
86 | - |
|
87 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
88 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) { |
|
89 | - $subscription->set_status( 'expired' ); |
|
90 | - $subscription->save(); |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Logs cron runs. |
|
98 | - * |
|
99 | - */ |
|
100 | - public function log_cron_run() { |
|
101 | - wpinv_error_log( 'GetPaid Daily Cron' ); |
|
102 | - } |
|
15 | + /** |
|
16 | + * Class constructor. |
|
17 | + */ |
|
18 | + public function __construct(){ |
|
19 | + |
|
20 | + // Clear deprecated events. |
|
21 | + add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | + |
|
23 | + // (Maybe) schedule a cron that runs daily. |
|
24 | + add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | + |
|
26 | + // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | + add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | + add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | + |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * Schedules a cron to run every day at 7 a.m |
|
35 | + * |
|
36 | + */ |
|
37 | + public function maybe_create_scheduled_event() { |
|
38 | + |
|
39 | + if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
40 | + $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
41 | + wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
42 | + } |
|
43 | + |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Clears deprecated events. |
|
48 | + * |
|
49 | + */ |
|
50 | + public function maybe_clear_deprecated_events() { |
|
51 | + |
|
52 | + if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
53 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
54 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
55 | + update_option( 'wpinv_cleared_old_events', 1 ); |
|
56 | + } |
|
57 | + |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Fires the old hook for backwards compatibility. |
|
62 | + * |
|
63 | + */ |
|
64 | + public function backwards_compat() { |
|
65 | + do_action( 'wpinv_register_schedule_event_daily' ); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Expires expired subscriptions. |
|
70 | + * |
|
71 | + */ |
|
72 | + public function maybe_expire_subscriptions() { |
|
73 | + |
|
74 | + // Fetch expired subscriptions (skips those that expire today). |
|
75 | + $args = array( |
|
76 | + 'number' => -1, |
|
77 | + 'count_total' => false, |
|
78 | + 'status' => 'trialling active failing cancelled', |
|
79 | + 'date_expires_query' => array( |
|
80 | + 'before' => 'today', |
|
81 | + 'inclusive' => false, |
|
82 | + ), |
|
83 | + ); |
|
84 | + |
|
85 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
86 | + |
|
87 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
88 | + if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) { |
|
89 | + $subscription->set_status( 'expired' ); |
|
90 | + $subscription->save(); |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Logs cron runs. |
|
98 | + * |
|
99 | + */ |
|
100 | + public function log_cron_run() { |
|
101 | + wpinv_error_log( 'GetPaid Daily Cron' ); |
|
102 | + } |
|
103 | 103 | |
104 | 104 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Daily maintenance class. |
@@ -15,18 +15,18 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * Class constructor. |
17 | 17 | */ |
18 | - public function __construct(){ |
|
18 | + public function __construct() { |
|
19 | 19 | |
20 | 20 | // Clear deprecated events. |
21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
21 | + add_action('wp', array($this, 'maybe_clear_deprecated_events')); |
|
22 | 22 | |
23 | 23 | // (Maybe) schedule a cron that runs daily. |
24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
24 | + add_action('wp', array($this, 'maybe_create_scheduled_event')); |
|
25 | 25 | |
26 | 26 | // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
27 | + add_action('getpaid_daily_maintenance', array($this, 'log_cron_run')); |
|
28 | + add_action('getpaid_daily_maintenance', array($this, 'backwards_compat')); |
|
29 | + add_action('getpaid_daily_maintenance', array($this, 'maybe_expire_subscriptions')); |
|
30 | 30 | |
31 | 31 | } |
32 | 32 | |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function maybe_create_scheduled_event() { |
38 | 38 | |
39 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
40 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
41 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
39 | + if (!wp_next_scheduled('getpaid_daily_maintenance')) { |
|
40 | + $timestamp = strtotime('tomorrow 07:00:00', current_time('timestamp')); |
|
41 | + wp_schedule_event($timestamp, 'daily', 'getpaid_daily_maintenance'); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | } |
@@ -49,10 +49,10 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function maybe_clear_deprecated_events() { |
51 | 51 | |
52 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
53 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
54 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
55 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
52 | + if (!get_option('wpinv_cleared_old_events')) { |
|
53 | + wp_clear_scheduled_hook('wpinv_register_schedule_event_twicedaily'); |
|
54 | + wp_clear_scheduled_hook('wpinv_register_schedule_event_daily'); |
|
55 | + update_option('wpinv_cleared_old_events', 1); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * |
63 | 63 | */ |
64 | 64 | public function backwards_compat() { |
65 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
65 | + do_action('wpinv_register_schedule_event_daily'); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | public function maybe_expire_subscriptions() { |
73 | 73 | |
74 | 74 | // Fetch expired subscriptions (skips those that expire today). |
75 | - $args = array( |
|
75 | + $args = array( |
|
76 | 76 | 'number' => -1, |
77 | 77 | 'count_total' => false, |
78 | 78 | 'status' => 'trialling active failing cancelled', |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | ), |
83 | 83 | ); |
84 | 84 | |
85 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
85 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
86 | 86 | |
87 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
88 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) { |
|
89 | - $subscription->set_status( 'expired' ); |
|
87 | + foreach ($subscriptions->get_results() as $subscription) { |
|
88 | + if (apply_filters('getpaid_daily_maintenance_should_expire_subscription', true, $subscription)) { |
|
89 | + $subscription->set_status('expired'); |
|
90 | 90 | $subscription->save(); |
91 | 91 | } |
92 | 92 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * |
99 | 99 | */ |
100 | 100 | public function log_cron_run() { |
101 | - wpinv_error_log( 'GetPaid Daily Cron' ); |
|
101 | + wpinv_error_log('GetPaid Daily Cron'); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | } |