@@ -13,47 +13,47 @@ discard block |
||
13 | 13 | class GetPaid_Bank_Transfer_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'bank_transfer'; |
21 | 21 | |
22 | - /** |
|
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - protected $supports = array( |
|
28 | - 'subscription', |
|
29 | - 'addons', |
|
30 | - 'single_subscription_group', |
|
31 | - 'multiple_subscription_groups', |
|
32 | - 'subscription_date_change', |
|
33 | - 'subscription_bill_times_change', |
|
34 | - ); |
|
22 | + /** |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + protected $supports = array( |
|
28 | + 'subscription', |
|
29 | + 'addons', |
|
30 | + 'single_subscription_group', |
|
31 | + 'multiple_subscription_groups', |
|
32 | + 'subscription_date_change', |
|
33 | + 'subscription_bill_times_change', |
|
34 | + ); |
|
35 | + |
|
36 | + /** |
|
37 | + * Payment method order. |
|
38 | + * |
|
39 | + * @var int |
|
40 | + */ |
|
41 | + public $order = 8; |
|
42 | + |
|
43 | + /** |
|
44 | + * Bank transfer instructions. |
|
45 | + */ |
|
46 | + public $instructions; |
|
35 | 47 | |
36 | 48 | /** |
37 | - * Payment method order. |
|
38 | - * |
|
39 | - * @var int |
|
40 | - */ |
|
41 | - public $order = 8; |
|
42 | - |
|
43 | - /** |
|
44 | - * Bank transfer instructions. |
|
45 | - */ |
|
46 | - public $instructions; |
|
47 | - |
|
48 | - /** |
|
49 | - * Locale array. |
|
50 | - */ |
|
51 | - public $locale; |
|
49 | + * Locale array. |
|
50 | + */ |
|
51 | + public $locale; |
|
52 | 52 | |
53 | 53 | /** |
54 | - * Class constructor. |
|
55 | - */ |
|
56 | - public function __construct() { |
|
54 | + * Class constructor. |
|
55 | + */ |
|
56 | + public function __construct() { |
|
57 | 57 | parent::__construct(); |
58 | 58 | |
59 | 59 | $this->title = __( 'Direct bank transfer', 'invoicing' ); |
@@ -61,43 +61,43 @@ discard block |
||
61 | 61 | $this->checkout_button_text = __( 'Proceed', 'invoicing' ); |
62 | 62 | $this->instructions = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) ); |
63 | 63 | |
64 | - add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
65 | - add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
66 | - add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
67 | - add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
68 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ), 12, 2 ); |
|
69 | - add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 ); |
|
70 | - |
|
71 | - add_filter( 'wpinv_' . $this->id . '_support_subscription', array( $this, 'supports_subscription' ), 20, 1 ); |
|
72 | - add_filter( 'getpaid_' . $this->id . '_support_subscription', array( $this, 'supports_subscription' ), 20, 1 ); |
|
73 | - add_filter( 'getpaid_' . $this->id . '_supports_subscription', array( $this, 'supports_subscription' ), 20, 1 ); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Check gateway supports for subscription. |
|
78 | - * |
|
79 | - * @since 2.8.24 |
|
80 | - * |
|
81 | - * @param bool $supports True if supports else False. |
|
82 | - * @return bool True if supports else False. |
|
83 | - */ |
|
84 | - public function supports_subscription( $supports ) { |
|
85 | - if ( $supports && (int) $this->get_option( 'no_subscription' ) ) { |
|
86 | - $supports = false; |
|
87 | - } |
|
88 | - |
|
89 | - return $supports; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Process Payment. |
|
94 | - * |
|
95 | - * @param WPInv_Invoice $invoice Invoice. |
|
96 | - * @param array $submission_data Posted checkout fields. |
|
97 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
98 | - * @return array |
|
99 | - */ |
|
100 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
64 | + add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
65 | + add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
66 | + add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
67 | + add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
68 | + add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ), 12, 2 ); |
|
69 | + add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 ); |
|
70 | + |
|
71 | + add_filter( 'wpinv_' . $this->id . '_support_subscription', array( $this, 'supports_subscription' ), 20, 1 ); |
|
72 | + add_filter( 'getpaid_' . $this->id . '_support_subscription', array( $this, 'supports_subscription' ), 20, 1 ); |
|
73 | + add_filter( 'getpaid_' . $this->id . '_supports_subscription', array( $this, 'supports_subscription' ), 20, 1 ); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Check gateway supports for subscription. |
|
78 | + * |
|
79 | + * @since 2.8.24 |
|
80 | + * |
|
81 | + * @param bool $supports True if supports else False. |
|
82 | + * @return bool True if supports else False. |
|
83 | + */ |
|
84 | + public function supports_subscription( $supports ) { |
|
85 | + if ( $supports && (int) $this->get_option( 'no_subscription' ) ) { |
|
86 | + $supports = false; |
|
87 | + } |
|
88 | + |
|
89 | + return $supports; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Process Payment. |
|
94 | + * |
|
95 | + * @param WPInv_Invoice $invoice Invoice. |
|
96 | + * @param array $submission_data Posted checkout fields. |
|
97 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
98 | + * @return array |
|
99 | + */ |
|
100 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
101 | 101 | |
102 | 102 | // Add a transaction id. |
103 | 103 | $invoice->set_transaction_id( $invoice->generate_key( 'bt_' ) ); |
@@ -118,66 +118,66 @@ discard block |
||
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
121 | - * Output for the order received page. |
|
122 | - * |
|
123 | - * @param WPInv_Invoice $invoice Invoice. |
|
124 | - */ |
|
125 | - public function thankyou_page( $invoice ) { |
|
121 | + * Output for the order received page. |
|
122 | + * |
|
123 | + * @param WPInv_Invoice $invoice Invoice. |
|
124 | + */ |
|
125 | + public function thankyou_page( $invoice ) { |
|
126 | 126 | |
127 | 127 | if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
128 | 128 | |
129 | - echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
129 | + echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
130 | 130 | |
131 | 131 | if ( ! empty( $this->instructions ) ) { |
132 | 132 | echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) ); |
133 | - } |
|
133 | + } |
|
134 | 134 | |
135 | - $this->bank_details( $invoice ); |
|
135 | + $this->bank_details( $invoice ); |
|
136 | 136 | |
137 | - echo '</div>'; |
|
137 | + echo '</div>'; |
|
138 | 138 | |
139 | 139 | } |
140 | 140 | |
141 | - } |
|
141 | + } |
|
142 | 142 | |
143 | 143 | /** |
144 | - * Add content to the WPI emails. |
|
145 | - * |
|
146 | - * @param WPInv_Invoice $invoice Invoice. |
|
147 | - * @param string $email_type Email format: plain text or HTML. |
|
148 | - * @param bool $sent_to_admin Sent to admin. |
|
149 | - */ |
|
150 | - public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
144 | + * Add content to the WPI emails. |
|
145 | + * |
|
146 | + * @param WPInv_Invoice $invoice Invoice. |
|
147 | + * @param string $email_type Email format: plain text or HTML. |
|
148 | + * @param bool $sent_to_admin Sent to admin. |
|
149 | + */ |
|
150 | + public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
151 | 151 | |
152 | - if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
152 | + if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
153 | 153 | |
154 | - echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
154 | + echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
155 | 155 | |
156 | - if ( $this->instructions ) { |
|
157 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
156 | + if ( $this->instructions ) { |
|
157 | + echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
158 | 158 | } |
159 | 159 | |
160 | - $this->bank_details( $invoice ); |
|
160 | + $this->bank_details( $invoice ); |
|
161 | 161 | |
162 | - echo '</div>'; |
|
162 | + echo '</div>'; |
|
163 | 163 | |
164 | - } |
|
164 | + } |
|
165 | 165 | |
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
169 | - * Get bank details and place into a list format. |
|
170 | - * |
|
171 | - * @param WPInv_Invoice $invoice Invoice. |
|
172 | - */ |
|
173 | - protected function bank_details( $invoice ) { |
|
169 | + * Get bank details and place into a list format. |
|
170 | + * |
|
171 | + * @param WPInv_Invoice $invoice Invoice. |
|
172 | + */ |
|
173 | + protected function bank_details( $invoice ) { |
|
174 | 174 | |
175 | - // Get the invoice country and country $locale. |
|
176 | - $country = $invoice->get_country(); |
|
177 | - $locale = $this->get_country_locale(); |
|
175 | + // Get the invoice country and country $locale. |
|
176 | + $country = $invoice->get_country(); |
|
177 | + $locale = $this->get_country_locale(); |
|
178 | 178 | |
179 | - // Get shortcode label in the $locale array and use appropriate one. |
|
180 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
179 | + // Get shortcode label in the $locale array and use appropriate one. |
|
180 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
181 | 181 | |
182 | 182 | $bank_fields = array( |
183 | 183 | 'ac_name' => __( 'Account Name', 'invoicing' ), |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | |
197 | 197 | if ( ! empty( $value ) ) { |
198 | 198 | $bank_info[ $field ] = array( |
199 | - 'label' => $label, |
|
200 | - 'value' => $value, |
|
201 | - ); |
|
199 | + 'label' => $label, |
|
200 | + 'value' => $value, |
|
201 | + ); |
|
202 | 202 | } |
203 | - } |
|
203 | + } |
|
204 | 204 | |
205 | 205 | $bank_info = apply_filters( 'wpinv_bank_info', $bank_info, $invoice ); |
206 | 206 | |
@@ -208,177 +208,177 @@ discard block |
||
208 | 208 | return; |
209 | 209 | } |
210 | 210 | |
211 | - echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL; |
|
211 | + echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL; |
|
212 | + |
|
213 | + echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
214 | + |
|
215 | + foreach ( $bank_info as $key => $data ) { |
|
216 | + echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL; |
|
217 | + } |
|
218 | + |
|
219 | + echo '</table>'; |
|
220 | + |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Get country locale if localized. |
|
225 | + * |
|
226 | + * @return array |
|
227 | + */ |
|
228 | + public function get_country_locale() { |
|
229 | + |
|
230 | + if ( empty( $this->locale ) ) { |
|
231 | + |
|
232 | + // Locale information to be used - only those that are not 'Sort Code'. |
|
233 | + $this->locale = apply_filters( |
|
234 | + 'getpaid_get_bank_transfer_locale', |
|
235 | + array( |
|
236 | + 'AU' => array( |
|
237 | + 'sortcode' => array( |
|
238 | + 'label' => __( 'BSB', 'invoicing' ), |
|
239 | + ), |
|
240 | + ), |
|
241 | + 'CA' => array( |
|
242 | + 'sortcode' => array( |
|
243 | + 'label' => __( 'Bank transit number', 'invoicing' ), |
|
244 | + ), |
|
245 | + ), |
|
246 | + 'IN' => array( |
|
247 | + 'sortcode' => array( |
|
248 | + 'label' => __( 'IFSC', 'invoicing' ), |
|
249 | + ), |
|
250 | + ), |
|
251 | + 'IT' => array( |
|
252 | + 'sortcode' => array( |
|
253 | + 'label' => __( 'Branch sort', 'invoicing' ), |
|
254 | + ), |
|
255 | + ), |
|
256 | + 'NZ' => array( |
|
257 | + 'sortcode' => array( |
|
258 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
259 | + ), |
|
260 | + ), |
|
261 | + 'SE' => array( |
|
262 | + 'sortcode' => array( |
|
263 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
264 | + ), |
|
265 | + ), |
|
266 | + 'US' => array( |
|
267 | + 'sortcode' => array( |
|
268 | + 'label' => __( 'Routing number', 'invoicing' ), |
|
269 | + ), |
|
270 | + ), |
|
271 | + 'ZA' => array( |
|
272 | + 'sortcode' => array( |
|
273 | + 'label' => __( 'Branch code', 'invoicing' ), |
|
274 | + ), |
|
275 | + ), |
|
276 | + ) |
|
277 | + ); |
|
278 | + |
|
279 | + } |
|
280 | + |
|
281 | + return $this->locale; |
|
282 | + |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * Filters the gateway settings. |
|
287 | + * |
|
288 | + * @param array $admin_settings |
|
289 | + */ |
|
290 | + public function admin_settings( $admin_settings ) { |
|
291 | + $admin_settings['bank_transfer_desc']['std'] = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ); |
|
292 | + $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
293 | + |
|
294 | + $_settings = array(); |
|
295 | + |
|
296 | + foreach ( $admin_settings as $key => $setting ) { |
|
297 | + $_settings[ $key ] = $setting; |
|
298 | + |
|
299 | + if ( $key == 'bank_transfer_active' ) { |
|
300 | + // Enable/disable subscriptions setting. |
|
301 | + $_settings['bank_transfer_no_subscription'] = array( |
|
302 | + 'id' => 'bank_transfer_no_subscription', |
|
303 | + 'type' => 'checkbox', |
|
304 | + 'name' => __( 'Disable Subscriptions', 'invoicing' ), |
|
305 | + 'desc' => __( 'Tick to disable support for recurring items.', 'invoicing' ), |
|
306 | + 'std' => 0 |
|
307 | + ); |
|
308 | + } |
|
309 | + } |
|
310 | + |
|
311 | + $admin_settings = $_settings; |
|
312 | + |
|
313 | + $locale = $this->get_country_locale(); |
|
314 | + |
|
315 | + // Get sortcode label in the $locale array and use appropriate one. |
|
316 | + $country = wpinv_default_billing_country(); |
|
317 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
318 | + |
|
319 | + $admin_settings['bank_transfer_ac_name'] = array( |
|
320 | + 'type' => 'text', |
|
321 | + 'id' => 'bank_transfer_ac_name', |
|
322 | + 'name' => __( 'Account Name', 'invoicing' ), |
|
323 | + ); |
|
324 | + |
|
325 | + $admin_settings['bank_transfer_ac_no'] = array( |
|
326 | + 'type' => 'text', |
|
327 | + 'id' => 'bank_transfer_ac_no', |
|
328 | + 'name' => __( 'Account Number', 'invoicing' ), |
|
329 | + ); |
|
330 | + |
|
331 | + $admin_settings['bank_transfer_bank_name'] = array( |
|
332 | + 'type' => 'text', |
|
333 | + 'id' => 'bank_transfer_bank_name', |
|
334 | + 'name' => __( 'Bank Name', 'invoicing' ), |
|
335 | + ); |
|
212 | 336 | |
213 | - echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
337 | + $admin_settings['bank_transfer_ifsc'] = array( |
|
338 | + 'type' => 'text', |
|
339 | + 'id' => 'bank_transfer_ifsc', |
|
340 | + 'name' => __( 'IFSC Code', 'invoicing' ), |
|
341 | + ); |
|
342 | + |
|
343 | + $admin_settings['bank_transfer_iban'] = array( |
|
344 | + 'type' => 'text', |
|
345 | + 'id' => 'bank_transfer_iban', |
|
346 | + 'name' => __( 'IBAN', 'invoicing' ), |
|
347 | + ); |
|
348 | + |
|
349 | + $admin_settings['bank_transfer_bic'] = array( |
|
350 | + 'type' => 'text', |
|
351 | + 'id' => 'bank_transfer_bic', |
|
352 | + 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
|
353 | + ); |
|
214 | 354 | |
215 | - foreach ( $bank_info as $key => $data ) { |
|
216 | - echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL; |
|
217 | - } |
|
355 | + $admin_settings['bank_transfer_sort_code'] = array( |
|
356 | + 'type' => 'text', |
|
357 | + 'id' => 'bank_transfer_sort_code', |
|
358 | + 'name' => $sortcode, |
|
359 | + ); |
|
218 | 360 | |
219 | - echo '</table>'; |
|
361 | + $admin_settings['bank_transfer_info'] = array( |
|
362 | + 'id' => 'bank_transfer_info', |
|
363 | + 'name' => __( 'Instructions', 'invoicing' ), |
|
364 | + 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
|
365 | + 'type' => 'textarea', |
|
366 | + 'std' => __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ), |
|
367 | + 'cols' => 50, |
|
368 | + 'rows' => 5, |
|
369 | + ); |
|
220 | 370 | |
371 | + return $admin_settings; |
|
221 | 372 | } |
222 | 373 | |
223 | 374 | /** |
224 | - * Get country locale if localized. |
|
225 | - * |
|
226 | - * @return array |
|
227 | - */ |
|
228 | - public function get_country_locale() { |
|
229 | - |
|
230 | - if ( empty( $this->locale ) ) { |
|
231 | - |
|
232 | - // Locale information to be used - only those that are not 'Sort Code'. |
|
233 | - $this->locale = apply_filters( |
|
234 | - 'getpaid_get_bank_transfer_locale', |
|
235 | - array( |
|
236 | - 'AU' => array( |
|
237 | - 'sortcode' => array( |
|
238 | - 'label' => __( 'BSB', 'invoicing' ), |
|
239 | - ), |
|
240 | - ), |
|
241 | - 'CA' => array( |
|
242 | - 'sortcode' => array( |
|
243 | - 'label' => __( 'Bank transit number', 'invoicing' ), |
|
244 | - ), |
|
245 | - ), |
|
246 | - 'IN' => array( |
|
247 | - 'sortcode' => array( |
|
248 | - 'label' => __( 'IFSC', 'invoicing' ), |
|
249 | - ), |
|
250 | - ), |
|
251 | - 'IT' => array( |
|
252 | - 'sortcode' => array( |
|
253 | - 'label' => __( 'Branch sort', 'invoicing' ), |
|
254 | - ), |
|
255 | - ), |
|
256 | - 'NZ' => array( |
|
257 | - 'sortcode' => array( |
|
258 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
259 | - ), |
|
260 | - ), |
|
261 | - 'SE' => array( |
|
262 | - 'sortcode' => array( |
|
263 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
264 | - ), |
|
265 | - ), |
|
266 | - 'US' => array( |
|
267 | - 'sortcode' => array( |
|
268 | - 'label' => __( 'Routing number', 'invoicing' ), |
|
269 | - ), |
|
270 | - ), |
|
271 | - 'ZA' => array( |
|
272 | - 'sortcode' => array( |
|
273 | - 'label' => __( 'Branch code', 'invoicing' ), |
|
274 | - ), |
|
275 | - ), |
|
276 | - ) |
|
277 | - ); |
|
278 | - |
|
279 | - } |
|
280 | - |
|
281 | - return $this->locale; |
|
282 | - |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * Filters the gateway settings. |
|
287 | - * |
|
288 | - * @param array $admin_settings |
|
289 | - */ |
|
290 | - public function admin_settings( $admin_settings ) { |
|
291 | - $admin_settings['bank_transfer_desc']['std'] = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ); |
|
292 | - $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
293 | - |
|
294 | - $_settings = array(); |
|
295 | - |
|
296 | - foreach ( $admin_settings as $key => $setting ) { |
|
297 | - $_settings[ $key ] = $setting; |
|
298 | - |
|
299 | - if ( $key == 'bank_transfer_active' ) { |
|
300 | - // Enable/disable subscriptions setting. |
|
301 | - $_settings['bank_transfer_no_subscription'] = array( |
|
302 | - 'id' => 'bank_transfer_no_subscription', |
|
303 | - 'type' => 'checkbox', |
|
304 | - 'name' => __( 'Disable Subscriptions', 'invoicing' ), |
|
305 | - 'desc' => __( 'Tick to disable support for recurring items.', 'invoicing' ), |
|
306 | - 'std' => 0 |
|
307 | - ); |
|
308 | - } |
|
309 | - } |
|
310 | - |
|
311 | - $admin_settings = $_settings; |
|
312 | - |
|
313 | - $locale = $this->get_country_locale(); |
|
314 | - |
|
315 | - // Get sortcode label in the $locale array and use appropriate one. |
|
316 | - $country = wpinv_default_billing_country(); |
|
317 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
318 | - |
|
319 | - $admin_settings['bank_transfer_ac_name'] = array( |
|
320 | - 'type' => 'text', |
|
321 | - 'id' => 'bank_transfer_ac_name', |
|
322 | - 'name' => __( 'Account Name', 'invoicing' ), |
|
323 | - ); |
|
324 | - |
|
325 | - $admin_settings['bank_transfer_ac_no'] = array( |
|
326 | - 'type' => 'text', |
|
327 | - 'id' => 'bank_transfer_ac_no', |
|
328 | - 'name' => __( 'Account Number', 'invoicing' ), |
|
329 | - ); |
|
330 | - |
|
331 | - $admin_settings['bank_transfer_bank_name'] = array( |
|
332 | - 'type' => 'text', |
|
333 | - 'id' => 'bank_transfer_bank_name', |
|
334 | - 'name' => __( 'Bank Name', 'invoicing' ), |
|
335 | - ); |
|
336 | - |
|
337 | - $admin_settings['bank_transfer_ifsc'] = array( |
|
338 | - 'type' => 'text', |
|
339 | - 'id' => 'bank_transfer_ifsc', |
|
340 | - 'name' => __( 'IFSC Code', 'invoicing' ), |
|
341 | - ); |
|
342 | - |
|
343 | - $admin_settings['bank_transfer_iban'] = array( |
|
344 | - 'type' => 'text', |
|
345 | - 'id' => 'bank_transfer_iban', |
|
346 | - 'name' => __( 'IBAN', 'invoicing' ), |
|
347 | - ); |
|
348 | - |
|
349 | - $admin_settings['bank_transfer_bic'] = array( |
|
350 | - 'type' => 'text', |
|
351 | - 'id' => 'bank_transfer_bic', |
|
352 | - 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
|
353 | - ); |
|
354 | - |
|
355 | - $admin_settings['bank_transfer_sort_code'] = array( |
|
356 | - 'type' => 'text', |
|
357 | - 'id' => 'bank_transfer_sort_code', |
|
358 | - 'name' => $sortcode, |
|
359 | - ); |
|
360 | - |
|
361 | - $admin_settings['bank_transfer_info'] = array( |
|
362 | - 'id' => 'bank_transfer_info', |
|
363 | - 'name' => __( 'Instructions', 'invoicing' ), |
|
364 | - 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
|
365 | - 'type' => 'textarea', |
|
366 | - 'std' => __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ), |
|
367 | - 'cols' => 50, |
|
368 | - 'rows' => 5, |
|
369 | - ); |
|
370 | - |
|
371 | - return $admin_settings; |
|
372 | - } |
|
373 | - |
|
374 | - /** |
|
375 | - * Processes invoice addons. |
|
376 | - * |
|
377 | - * @param WPInv_Invoice $invoice |
|
378 | - * @param GetPaid_Form_Item[] $items |
|
379 | - * @return WPInv_Invoice |
|
380 | - */ |
|
381 | - public function process_addons( $invoice, $items ) { |
|
375 | + * Processes invoice addons. |
|
376 | + * |
|
377 | + * @param WPInv_Invoice $invoice |
|
378 | + * @param GetPaid_Form_Item[] $items |
|
379 | + * @return WPInv_Invoice |
|
380 | + */ |
|
381 | + public function process_addons( $invoice, $items ) { |
|
382 | 382 | |
383 | 383 | foreach ( $items as $item ) { |
384 | 384 | $invoice->add_item( $item ); |
@@ -386,98 +386,98 @@ discard block |
||
386 | 386 | |
387 | 387 | $invoice->recalculate_total(); |
388 | 388 | $invoice->save(); |
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * (Maybe) renews a bank transfer subscription profile. |
|
393 | - * |
|
394 | - * |
|
395 | - * @param WPInv_Subscription $subscription |
|
396 | - */ |
|
397 | - public function maybe_renew_subscription( $subscription, $parent_invoice ) { |
|
398 | - // Ensure its our subscription && it's active. |
|
399 | - if ( ! empty( $parent_invoice ) && $this->id === $parent_invoice->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
400 | - add_filter( 'getpaid_invoice_notifications_is_payment_form_invoice', array( $this, 'force_is_payment_form_invoice' ), 10, 2 ); |
|
401 | - |
|
402 | - $invoice = $subscription->create_payment(); |
|
403 | - |
|
404 | - if ( ! empty( $invoice ) ) { |
|
405 | - $is_logged_in = is_user_logged_in(); |
|
406 | - |
|
407 | - // Cron run. |
|
408 | - if ( ! $is_logged_in ) { |
|
409 | - $note = wp_sprintf( __( 'Renewal %1$s created with the status "%2$s".', 'invoicing' ), $invoice->get_invoice_quote_type(), wpinv_status_nicename( $invoice->get_status(), $invoice ) ); |
|
410 | - |
|
411 | - $invoice->add_note( $note, false, $is_logged_in, ! $is_logged_in ); |
|
412 | - } |
|
413 | - } |
|
414 | - |
|
415 | - remove_filter( 'getpaid_invoice_notifications_is_payment_form_invoice', array( $this, 'force_is_payment_form_invoice' ), 10, 2 ); |
|
416 | - } |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * Process a bank transfer payment. |
|
421 | - * |
|
422 | - * |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * (Maybe) renews a bank transfer subscription profile. |
|
393 | + * |
|
394 | + * |
|
395 | + * @param WPInv_Subscription $subscription |
|
396 | + */ |
|
397 | + public function maybe_renew_subscription( $subscription, $parent_invoice ) { |
|
398 | + // Ensure its our subscription && it's active. |
|
399 | + if ( ! empty( $parent_invoice ) && $this->id === $parent_invoice->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
400 | + add_filter( 'getpaid_invoice_notifications_is_payment_form_invoice', array( $this, 'force_is_payment_form_invoice' ), 10, 2 ); |
|
401 | + |
|
402 | + $invoice = $subscription->create_payment(); |
|
403 | + |
|
404 | + if ( ! empty( $invoice ) ) { |
|
405 | + $is_logged_in = is_user_logged_in(); |
|
406 | + |
|
407 | + // Cron run. |
|
408 | + if ( ! $is_logged_in ) { |
|
409 | + $note = wp_sprintf( __( 'Renewal %1$s created with the status "%2$s".', 'invoicing' ), $invoice->get_invoice_quote_type(), wpinv_status_nicename( $invoice->get_status(), $invoice ) ); |
|
410 | + |
|
411 | + $invoice->add_note( $note, false, $is_logged_in, ! $is_logged_in ); |
|
412 | + } |
|
413 | + } |
|
414 | + |
|
415 | + remove_filter( 'getpaid_invoice_notifications_is_payment_form_invoice', array( $this, 'force_is_payment_form_invoice' ), 10, 2 ); |
|
416 | + } |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * Process a bank transfer payment. |
|
421 | + * |
|
422 | + * |
|
423 | 423 | * @param WPInv_Invoice $invoice |
424 | - */ |
|
425 | - public function invoice_paid( $invoice ) { |
|
426 | - |
|
427 | - // Abort if not paid by bank transfer. |
|
428 | - if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) { |
|
429 | - return; |
|
430 | - } |
|
431 | - |
|
432 | - // Is it a parent payment? |
|
433 | - if ( 0 == $invoice->get_parent_id() ) { |
|
434 | - |
|
435 | - // (Maybe) activate subscriptions. |
|
436 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
437 | - |
|
438 | - if ( ! empty( $subscriptions ) ) { |
|
439 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
440 | - |
|
441 | - foreach ( $subscriptions as $subscription ) { |
|
442 | - if ( $subscription->exists() ) { |
|
443 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
444 | - $expiry = gmdate( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
445 | - |
|
446 | - $subscription->set_next_renewal_date( $expiry ); |
|
447 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
448 | - $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ); |
|
449 | - $subscription->activate(); |
|
450 | - } |
|
451 | - } |
|
452 | - } |
|
453 | - } else { |
|
454 | - |
|
455 | - $subscription = getpaid_get_subscription( $invoice->get_subscription_id() ); |
|
456 | - |
|
457 | - // Renew the subscription. |
|
458 | - if ( $subscription && $subscription->exists() ) { |
|
459 | - $subscription->add_payment( array(), $invoice ); |
|
460 | - $subscription->renew( strtotime( $invoice->get_date_created() ) ); |
|
461 | - } |
|
462 | - } |
|
424 | + */ |
|
425 | + public function invoice_paid( $invoice ) { |
|
426 | + |
|
427 | + // Abort if not paid by bank transfer. |
|
428 | + if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) { |
|
429 | + return; |
|
430 | + } |
|
431 | + |
|
432 | + // Is it a parent payment? |
|
433 | + if ( 0 == $invoice->get_parent_id() ) { |
|
434 | + |
|
435 | + // (Maybe) activate subscriptions. |
|
436 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
437 | + |
|
438 | + if ( ! empty( $subscriptions ) ) { |
|
439 | + $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
440 | + |
|
441 | + foreach ( $subscriptions as $subscription ) { |
|
442 | + if ( $subscription->exists() ) { |
|
443 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
444 | + $expiry = gmdate( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
445 | + |
|
446 | + $subscription->set_next_renewal_date( $expiry ); |
|
447 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
448 | + $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ); |
|
449 | + $subscription->activate(); |
|
450 | + } |
|
451 | + } |
|
452 | + } |
|
453 | + } else { |
|
454 | + |
|
455 | + $subscription = getpaid_get_subscription( $invoice->get_subscription_id() ); |
|
456 | + |
|
457 | + // Renew the subscription. |
|
458 | + if ( $subscription && $subscription->exists() ) { |
|
459 | + $subscription->add_payment( array(), $invoice ); |
|
460 | + $subscription->renew( strtotime( $invoice->get_date_created() ) ); |
|
461 | + } |
|
462 | + } |
|
463 | 463 | |
464 | 464 | } |
465 | 465 | |
466 | - /** |
|
467 | - * Force created from payment false to allow email for auto renewal generation invoice. |
|
468 | - * |
|
469 | - * @since 2.8.11 |
|
470 | - * |
|
471 | - * @param bool $is_payment_form_invoice True when invoice created via payment form else false. |
|
472 | - * @param int $invoice Invoice ID. |
|
473 | - * @return bool True when invoice created via payment form else false. |
|
474 | - */ |
|
475 | - public function force_is_payment_form_invoice( $is_payment_form_invoice, $invoice ) { |
|
476 | - if ( $is_payment_form_invoice ) { |
|
477 | - $is_payment_form_invoice = false; |
|
478 | - } |
|
479 | - |
|
480 | - return $is_payment_form_invoice; |
|
481 | - } |
|
466 | + /** |
|
467 | + * Force created from payment false to allow email for auto renewal generation invoice. |
|
468 | + * |
|
469 | + * @since 2.8.11 |
|
470 | + * |
|
471 | + * @param bool $is_payment_form_invoice True when invoice created via payment form else false. |
|
472 | + * @param int $invoice Invoice ID. |
|
473 | + * @return bool True when invoice created via payment form else false. |
|
474 | + */ |
|
475 | + public function force_is_payment_form_invoice( $is_payment_form_invoice, $invoice ) { |
|
476 | + if ( $is_payment_form_invoice ) { |
|
477 | + $is_payment_form_invoice = false; |
|
478 | + } |
|
479 | + |
|
480 | + return $is_payment_form_invoice; |
|
481 | + } |
|
482 | 482 | |
483 | 483 | } |
@@ -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 | * Bank transfer Payment Gateway class. |
@@ -56,21 +56,21 @@ discard block |
||
56 | 56 | public function __construct() { |
57 | 57 | parent::__construct(); |
58 | 58 | |
59 | - $this->title = __( 'Direct bank transfer', 'invoicing' ); |
|
60 | - $this->method_title = __( 'Bank transfer', 'invoicing' ); |
|
61 | - $this->checkout_button_text = __( 'Proceed', 'invoicing' ); |
|
62 | - $this->instructions = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) ); |
|
63 | - |
|
64 | - add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
65 | - add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
66 | - add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
67 | - add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
68 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ), 12, 2 ); |
|
69 | - add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 ); |
|
70 | - |
|
71 | - add_filter( 'wpinv_' . $this->id . '_support_subscription', array( $this, 'supports_subscription' ), 20, 1 ); |
|
72 | - add_filter( 'getpaid_' . $this->id . '_support_subscription', array( $this, 'supports_subscription' ), 20, 1 ); |
|
73 | - add_filter( 'getpaid_' . $this->id . '_supports_subscription', array( $this, 'supports_subscription' ), 20, 1 ); |
|
59 | + $this->title = __('Direct bank transfer', 'invoicing'); |
|
60 | + $this->method_title = __('Bank transfer', 'invoicing'); |
|
61 | + $this->checkout_button_text = __('Proceed', 'invoicing'); |
|
62 | + $this->instructions = apply_filters('wpinv_bank_instructions', $this->get_option('info')); |
|
63 | + |
|
64 | + add_action('wpinv_receipt_end', array($this, 'thankyou_page')); |
|
65 | + add_action('getpaid_invoice_line_items', array($this, 'thankyou_page'), 40); |
|
66 | + add_action('wpinv_pdf_content_billing', array($this, 'thankyou_page'), 11); |
|
67 | + add_action('wpinv_email_invoice_details', array($this, 'email_instructions'), 10, 3); |
|
68 | + add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription'), 12, 2); |
|
69 | + add_action('getpaid_invoice_status_publish', array($this, 'invoice_paid'), 20); |
|
70 | + |
|
71 | + add_filter('wpinv_' . $this->id . '_support_subscription', array($this, 'supports_subscription'), 20, 1); |
|
72 | + add_filter('getpaid_' . $this->id . '_support_subscription', array($this, 'supports_subscription'), 20, 1); |
|
73 | + add_filter('getpaid_' . $this->id . '_supports_subscription', array($this, 'supports_subscription'), 20, 1); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | * @param bool $supports True if supports else False. |
82 | 82 | * @return bool True if supports else False. |
83 | 83 | */ |
84 | - public function supports_subscription( $supports ) { |
|
85 | - if ( $supports && (int) $this->get_option( 'no_subscription' ) ) { |
|
84 | + public function supports_subscription($supports) { |
|
85 | + if ($supports && (int) $this->get_option('no_subscription')) { |
|
86 | 86 | $supports = false; |
87 | 87 | } |
88 | 88 | |
@@ -97,23 +97,23 @@ discard block |
||
97 | 97 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
98 | 98 | * @return array |
99 | 99 | */ |
100 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
100 | + public function process_payment($invoice, $submission_data, $submission) { |
|
101 | 101 | |
102 | 102 | // Add a transaction id. |
103 | - $invoice->set_transaction_id( $invoice->generate_key( 'bt_' ) ); |
|
103 | + $invoice->set_transaction_id($invoice->generate_key('bt_')); |
|
104 | 104 | |
105 | 105 | // Set it as pending payment. |
106 | - if ( ! $invoice->needs_payment() ) { |
|
106 | + if (!$invoice->needs_payment()) { |
|
107 | 107 | $invoice->mark_paid(); |
108 | - } elseif ( ! $invoice->is_paid() ) { |
|
109 | - $invoice->set_status( 'wpi-onhold' ); |
|
108 | + } elseif (!$invoice->is_paid()) { |
|
109 | + $invoice->set_status('wpi-onhold'); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | // Save it. |
113 | 113 | $invoice->save(); |
114 | 114 | |
115 | 115 | // Send to the success page. |
116 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
116 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
117 | 117 | |
118 | 118 | } |
119 | 119 | |
@@ -122,17 +122,17 @@ discard block |
||
122 | 122 | * |
123 | 123 | * @param WPInv_Invoice $invoice Invoice. |
124 | 124 | */ |
125 | - public function thankyou_page( $invoice ) { |
|
125 | + public function thankyou_page($invoice) { |
|
126 | 126 | |
127 | - if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
127 | + if ('bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment()) { |
|
128 | 128 | |
129 | 129 | echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
130 | 130 | |
131 | - if ( ! empty( $this->instructions ) ) { |
|
132 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) ); |
|
131 | + if (!empty($this->instructions)) { |
|
132 | + echo wp_kses_post(wpautop(wptexturize($this->instructions))); |
|
133 | 133 | } |
134 | 134 | |
135 | - $this->bank_details( $invoice ); |
|
135 | + $this->bank_details($invoice); |
|
136 | 136 | |
137 | 137 | echo '</div>'; |
138 | 138 | |
@@ -147,17 +147,17 @@ discard block |
||
147 | 147 | * @param string $email_type Email format: plain text or HTML. |
148 | 148 | * @param bool $sent_to_admin Sent to admin. |
149 | 149 | */ |
150 | - public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
150 | + public function email_instructions($invoice, $email_type, $sent_to_admin) { |
|
151 | 151 | |
152 | - if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
152 | + if (!$sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment()) { |
|
153 | 153 | |
154 | 154 | echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
155 | 155 | |
156 | - if ( $this->instructions ) { |
|
157 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
156 | + if ($this->instructions) { |
|
157 | + echo wp_kses_post(wpautop(wptexturize($this->instructions)) . PHP_EOL); |
|
158 | 158 | } |
159 | 159 | |
160 | - $this->bank_details( $invoice ); |
|
160 | + $this->bank_details($invoice); |
|
161 | 161 | |
162 | 162 | echo '</div>'; |
163 | 163 | |
@@ -170,50 +170,50 @@ discard block |
||
170 | 170 | * |
171 | 171 | * @param WPInv_Invoice $invoice Invoice. |
172 | 172 | */ |
173 | - protected function bank_details( $invoice ) { |
|
173 | + protected function bank_details($invoice) { |
|
174 | 174 | |
175 | 175 | // Get the invoice country and country $locale. |
176 | 176 | $country = $invoice->get_country(); |
177 | 177 | $locale = $this->get_country_locale(); |
178 | 178 | |
179 | 179 | // Get shortcode label in the $locale array and use appropriate one. |
180 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
180 | + $sortcode = isset($locale[$country]['sortcode']['label']) ? $locale[$country]['sortcode']['label'] : __('Sort code', 'invoicing'); |
|
181 | 181 | |
182 | 182 | $bank_fields = array( |
183 | - 'ac_name' => __( 'Account Name', 'invoicing' ), |
|
184 | - 'ac_no' => __( 'Account Number', 'invoicing' ), |
|
185 | - 'bank_name' => __( 'Bank Name', 'invoicing' ), |
|
186 | - 'ifsc' => __( 'IFSC code', 'invoicing' ), |
|
187 | - 'iban' => __( 'IBAN', 'invoicing' ), |
|
188 | - 'bic' => __( 'BIC/Swift code', 'invoicing' ), |
|
183 | + 'ac_name' => __('Account Name', 'invoicing'), |
|
184 | + 'ac_no' => __('Account Number', 'invoicing'), |
|
185 | + 'bank_name' => __('Bank Name', 'invoicing'), |
|
186 | + 'ifsc' => __('IFSC code', 'invoicing'), |
|
187 | + 'iban' => __('IBAN', 'invoicing'), |
|
188 | + 'bic' => __('BIC/Swift code', 'invoicing'), |
|
189 | 189 | 'sort_code' => $sortcode, |
190 | 190 | ); |
191 | 191 | |
192 | 192 | $bank_info = array(); |
193 | 193 | |
194 | - foreach ( $bank_fields as $field => $label ) { |
|
195 | - $value = $this->get_option( $field ); |
|
194 | + foreach ($bank_fields as $field => $label) { |
|
195 | + $value = $this->get_option($field); |
|
196 | 196 | |
197 | - if ( ! empty( $value ) ) { |
|
198 | - $bank_info[ $field ] = array( |
|
197 | + if (!empty($value)) { |
|
198 | + $bank_info[$field] = array( |
|
199 | 199 | 'label' => $label, |
200 | 200 | 'value' => $value, |
201 | 201 | ); |
202 | 202 | } |
203 | 203 | } |
204 | 204 | |
205 | - $bank_info = apply_filters( 'wpinv_bank_info', $bank_info, $invoice ); |
|
205 | + $bank_info = apply_filters('wpinv_bank_info', $bank_info, $invoice); |
|
206 | 206 | |
207 | - if ( empty( $bank_info ) ) { |
|
207 | + if (empty($bank_info)) { |
|
208 | 208 | return; |
209 | 209 | } |
210 | 210 | |
211 | - echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL; |
|
211 | + echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html(apply_filters('wpinv_receipt_bank_details_title', __('Bank Details', 'invoicing'), $invoice)) . '</h3>' . PHP_EOL; |
|
212 | 212 | |
213 | 213 | echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
214 | 214 | |
215 | - foreach ( $bank_info as $key => $data ) { |
|
216 | - echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL; |
|
215 | + foreach ($bank_info as $key => $data) { |
|
216 | + echo "<tr class='getpaid-bank-transfer-" . esc_attr($key) . "'><th class='font-weight-bold'>" . wp_kses_post($data['label']) . "</th><td class='w-75'>" . wp_kses_post(wptexturize($data['value'])) . '</td></tr>' . PHP_EOL; |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | echo '</table>'; |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | */ |
228 | 228 | public function get_country_locale() { |
229 | 229 | |
230 | - if ( empty( $this->locale ) ) { |
|
230 | + if (empty($this->locale)) { |
|
231 | 231 | |
232 | 232 | // Locale information to be used - only those that are not 'Sort Code'. |
233 | 233 | $this->locale = apply_filters( |
@@ -235,42 +235,42 @@ discard block |
||
235 | 235 | array( |
236 | 236 | 'AU' => array( |
237 | 237 | 'sortcode' => array( |
238 | - 'label' => __( 'BSB', 'invoicing' ), |
|
238 | + 'label' => __('BSB', 'invoicing'), |
|
239 | 239 | ), |
240 | 240 | ), |
241 | 241 | 'CA' => array( |
242 | 242 | 'sortcode' => array( |
243 | - 'label' => __( 'Bank transit number', 'invoicing' ), |
|
243 | + 'label' => __('Bank transit number', 'invoicing'), |
|
244 | 244 | ), |
245 | 245 | ), |
246 | 246 | 'IN' => array( |
247 | 247 | 'sortcode' => array( |
248 | - 'label' => __( 'IFSC', 'invoicing' ), |
|
248 | + 'label' => __('IFSC', 'invoicing'), |
|
249 | 249 | ), |
250 | 250 | ), |
251 | 251 | 'IT' => array( |
252 | 252 | 'sortcode' => array( |
253 | - 'label' => __( 'Branch sort', 'invoicing' ), |
|
253 | + 'label' => __('Branch sort', 'invoicing'), |
|
254 | 254 | ), |
255 | 255 | ), |
256 | 256 | 'NZ' => array( |
257 | 257 | 'sortcode' => array( |
258 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
258 | + 'label' => __('Bank code', 'invoicing'), |
|
259 | 259 | ), |
260 | 260 | ), |
261 | 261 | 'SE' => array( |
262 | 262 | 'sortcode' => array( |
263 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
263 | + 'label' => __('Bank code', 'invoicing'), |
|
264 | 264 | ), |
265 | 265 | ), |
266 | 266 | 'US' => array( |
267 | 267 | 'sortcode' => array( |
268 | - 'label' => __( 'Routing number', 'invoicing' ), |
|
268 | + 'label' => __('Routing number', 'invoicing'), |
|
269 | 269 | ), |
270 | 270 | ), |
271 | 271 | 'ZA' => array( |
272 | 272 | 'sortcode' => array( |
273 | - 'label' => __( 'Branch code', 'invoicing' ), |
|
273 | + 'label' => __('Branch code', 'invoicing'), |
|
274 | 274 | ), |
275 | 275 | ), |
276 | 276 | ) |
@@ -287,22 +287,22 @@ discard block |
||
287 | 287 | * |
288 | 288 | * @param array $admin_settings |
289 | 289 | */ |
290 | - public function admin_settings( $admin_settings ) { |
|
291 | - $admin_settings['bank_transfer_desc']['std'] = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ); |
|
292 | - $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
290 | + public function admin_settings($admin_settings) { |
|
291 | + $admin_settings['bank_transfer_desc']['std'] = __("Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing'); |
|
292 | + $admin_settings['bank_transfer_active']['desc'] = __('Enable bank transfer', 'invoicing'); |
|
293 | 293 | |
294 | 294 | $_settings = array(); |
295 | 295 | |
296 | - foreach ( $admin_settings as $key => $setting ) { |
|
297 | - $_settings[ $key ] = $setting; |
|
296 | + foreach ($admin_settings as $key => $setting) { |
|
297 | + $_settings[$key] = $setting; |
|
298 | 298 | |
299 | - if ( $key == 'bank_transfer_active' ) { |
|
299 | + if ($key == 'bank_transfer_active') { |
|
300 | 300 | // Enable/disable subscriptions setting. |
301 | 301 | $_settings['bank_transfer_no_subscription'] = array( |
302 | 302 | 'id' => 'bank_transfer_no_subscription', |
303 | 303 | 'type' => 'checkbox', |
304 | - 'name' => __( 'Disable Subscriptions', 'invoicing' ), |
|
305 | - 'desc' => __( 'Tick to disable support for recurring items.', 'invoicing' ), |
|
304 | + 'name' => __('Disable Subscriptions', 'invoicing'), |
|
305 | + 'desc' => __('Tick to disable support for recurring items.', 'invoicing'), |
|
306 | 306 | 'std' => 0 |
307 | 307 | ); |
308 | 308 | } |
@@ -310,46 +310,46 @@ discard block |
||
310 | 310 | |
311 | 311 | $admin_settings = $_settings; |
312 | 312 | |
313 | - $locale = $this->get_country_locale(); |
|
313 | + $locale = $this->get_country_locale(); |
|
314 | 314 | |
315 | 315 | // Get sortcode label in the $locale array and use appropriate one. |
316 | 316 | $country = wpinv_default_billing_country(); |
317 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
317 | + $sortcode = isset($locale[$country]['sortcode']['label']) ? $locale[$country]['sortcode']['label'] : __('Sort code', 'invoicing'); |
|
318 | 318 | |
319 | 319 | $admin_settings['bank_transfer_ac_name'] = array( |
320 | 320 | 'type' => 'text', |
321 | 321 | 'id' => 'bank_transfer_ac_name', |
322 | - 'name' => __( 'Account Name', 'invoicing' ), |
|
322 | + 'name' => __('Account Name', 'invoicing'), |
|
323 | 323 | ); |
324 | 324 | |
325 | 325 | $admin_settings['bank_transfer_ac_no'] = array( |
326 | 326 | 'type' => 'text', |
327 | 327 | 'id' => 'bank_transfer_ac_no', |
328 | - 'name' => __( 'Account Number', 'invoicing' ), |
|
328 | + 'name' => __('Account Number', 'invoicing'), |
|
329 | 329 | ); |
330 | 330 | |
331 | 331 | $admin_settings['bank_transfer_bank_name'] = array( |
332 | 332 | 'type' => 'text', |
333 | 333 | 'id' => 'bank_transfer_bank_name', |
334 | - 'name' => __( 'Bank Name', 'invoicing' ), |
|
334 | + 'name' => __('Bank Name', 'invoicing'), |
|
335 | 335 | ); |
336 | 336 | |
337 | 337 | $admin_settings['bank_transfer_ifsc'] = array( |
338 | 338 | 'type' => 'text', |
339 | 339 | 'id' => 'bank_transfer_ifsc', |
340 | - 'name' => __( 'IFSC Code', 'invoicing' ), |
|
340 | + 'name' => __('IFSC Code', 'invoicing'), |
|
341 | 341 | ); |
342 | 342 | |
343 | 343 | $admin_settings['bank_transfer_iban'] = array( |
344 | 344 | 'type' => 'text', |
345 | 345 | 'id' => 'bank_transfer_iban', |
346 | - 'name' => __( 'IBAN', 'invoicing' ), |
|
346 | + 'name' => __('IBAN', 'invoicing'), |
|
347 | 347 | ); |
348 | 348 | |
349 | 349 | $admin_settings['bank_transfer_bic'] = array( |
350 | 350 | 'type' => 'text', |
351 | 351 | 'id' => 'bank_transfer_bic', |
352 | - 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
|
352 | + 'name' => __('BIC/Swift Code', 'invoicing'), |
|
353 | 353 | ); |
354 | 354 | |
355 | 355 | $admin_settings['bank_transfer_sort_code'] = array( |
@@ -360,10 +360,10 @@ discard block |
||
360 | 360 | |
361 | 361 | $admin_settings['bank_transfer_info'] = array( |
362 | 362 | 'id' => 'bank_transfer_info', |
363 | - 'name' => __( 'Instructions', 'invoicing' ), |
|
364 | - 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
|
363 | + 'name' => __('Instructions', 'invoicing'), |
|
364 | + 'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'), |
|
365 | 365 | 'type' => 'textarea', |
366 | - 'std' => __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ), |
|
366 | + 'std' => __("Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing'), |
|
367 | 367 | 'cols' => 50, |
368 | 368 | 'rows' => 5, |
369 | 369 | ); |
@@ -378,10 +378,10 @@ discard block |
||
378 | 378 | * @param GetPaid_Form_Item[] $items |
379 | 379 | * @return WPInv_Invoice |
380 | 380 | */ |
381 | - public function process_addons( $invoice, $items ) { |
|
381 | + public function process_addons($invoice, $items) { |
|
382 | 382 | |
383 | - foreach ( $items as $item ) { |
|
384 | - $invoice->add_item( $item ); |
|
383 | + foreach ($items as $item) { |
|
384 | + $invoice->add_item($item); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | $invoice->recalculate_total(); |
@@ -394,25 +394,25 @@ discard block |
||
394 | 394 | * |
395 | 395 | * @param WPInv_Subscription $subscription |
396 | 396 | */ |
397 | - public function maybe_renew_subscription( $subscription, $parent_invoice ) { |
|
397 | + public function maybe_renew_subscription($subscription, $parent_invoice) { |
|
398 | 398 | // Ensure its our subscription && it's active. |
399 | - if ( ! empty( $parent_invoice ) && $this->id === $parent_invoice->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
400 | - add_filter( 'getpaid_invoice_notifications_is_payment_form_invoice', array( $this, 'force_is_payment_form_invoice' ), 10, 2 ); |
|
399 | + if (!empty($parent_invoice) && $this->id === $parent_invoice->get_gateway() && $subscription->has_status('active trialling')) { |
|
400 | + add_filter('getpaid_invoice_notifications_is_payment_form_invoice', array($this, 'force_is_payment_form_invoice'), 10, 2); |
|
401 | 401 | |
402 | 402 | $invoice = $subscription->create_payment(); |
403 | 403 | |
404 | - if ( ! empty( $invoice ) ) { |
|
404 | + if (!empty($invoice)) { |
|
405 | 405 | $is_logged_in = is_user_logged_in(); |
406 | 406 | |
407 | 407 | // Cron run. |
408 | - if ( ! $is_logged_in ) { |
|
409 | - $note = wp_sprintf( __( 'Renewal %1$s created with the status "%2$s".', 'invoicing' ), $invoice->get_invoice_quote_type(), wpinv_status_nicename( $invoice->get_status(), $invoice ) ); |
|
408 | + if (!$is_logged_in) { |
|
409 | + $note = wp_sprintf(__('Renewal %1$s created with the status "%2$s".', 'invoicing'), $invoice->get_invoice_quote_type(), wpinv_status_nicename($invoice->get_status(), $invoice)); |
|
410 | 410 | |
411 | - $invoice->add_note( $note, false, $is_logged_in, ! $is_logged_in ); |
|
411 | + $invoice->add_note($note, false, $is_logged_in, !$is_logged_in); |
|
412 | 412 | } |
413 | 413 | } |
414 | 414 | |
415 | - remove_filter( 'getpaid_invoice_notifications_is_payment_form_invoice', array( $this, 'force_is_payment_form_invoice' ), 10, 2 ); |
|
415 | + remove_filter('getpaid_invoice_notifications_is_payment_form_invoice', array($this, 'force_is_payment_form_invoice'), 10, 2); |
|
416 | 416 | } |
417 | 417 | } |
418 | 418 | |
@@ -422,42 +422,42 @@ discard block |
||
422 | 422 | * |
423 | 423 | * @param WPInv_Invoice $invoice |
424 | 424 | */ |
425 | - public function invoice_paid( $invoice ) { |
|
425 | + public function invoice_paid($invoice) { |
|
426 | 426 | |
427 | 427 | // Abort if not paid by bank transfer. |
428 | - if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) { |
|
428 | + if ($this->id !== $invoice->get_gateway() || !$invoice->is_recurring()) { |
|
429 | 429 | return; |
430 | 430 | } |
431 | 431 | |
432 | 432 | // Is it a parent payment? |
433 | - if ( 0 == $invoice->get_parent_id() ) { |
|
433 | + if (0 == $invoice->get_parent_id()) { |
|
434 | 434 | |
435 | 435 | // (Maybe) activate subscriptions. |
436 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
436 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
437 | 437 | |
438 | - if ( ! empty( $subscriptions ) ) { |
|
439 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
438 | + if (!empty($subscriptions)) { |
|
439 | + $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions); |
|
440 | 440 | |
441 | - foreach ( $subscriptions as $subscription ) { |
|
442 | - if ( $subscription->exists() ) { |
|
443 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
444 | - $expiry = gmdate( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
441 | + foreach ($subscriptions as $subscription) { |
|
442 | + if ($subscription->exists()) { |
|
443 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
444 | + $expiry = gmdate('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
445 | 445 | |
446 | - $subscription->set_next_renewal_date( $expiry ); |
|
447 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
448 | - $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ); |
|
446 | + $subscription->set_next_renewal_date($expiry); |
|
447 | + $subscription->set_date_created(current_time('mysql')); |
|
448 | + $subscription->set_profile_id('bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id()); |
|
449 | 449 | $subscription->activate(); |
450 | 450 | } |
451 | 451 | } |
452 | 452 | } |
453 | 453 | } else { |
454 | 454 | |
455 | - $subscription = getpaid_get_subscription( $invoice->get_subscription_id() ); |
|
455 | + $subscription = getpaid_get_subscription($invoice->get_subscription_id()); |
|
456 | 456 | |
457 | 457 | // Renew the subscription. |
458 | - if ( $subscription && $subscription->exists() ) { |
|
459 | - $subscription->add_payment( array(), $invoice ); |
|
460 | - $subscription->renew( strtotime( $invoice->get_date_created() ) ); |
|
458 | + if ($subscription && $subscription->exists()) { |
|
459 | + $subscription->add_payment(array(), $invoice); |
|
460 | + $subscription->renew(strtotime($invoice->get_date_created())); |
|
461 | 461 | } |
462 | 462 | } |
463 | 463 | |
@@ -472,8 +472,8 @@ discard block |
||
472 | 472 | * @param int $invoice Invoice ID. |
473 | 473 | * @return bool True when invoice created via payment form else false. |
474 | 474 | */ |
475 | - public function force_is_payment_form_invoice( $is_payment_form_invoice, $invoice ) { |
|
476 | - if ( $is_payment_form_invoice ) { |
|
475 | + public function force_is_payment_form_invoice($is_payment_form_invoice, $invoice) { |
|
476 | + if ($is_payment_form_invoice) { |
|
477 | 477 | $is_payment_form_invoice = false; |
478 | 478 | } |
479 | 479 |
@@ -17,402 +17,402 @@ |
||
17 | 17 | */ |
18 | 18 | class GetPaid_Admin_Setup_Wizard { |
19 | 19 | |
20 | - /** |
|
21 | - * @var string Current Step |
|
22 | - */ |
|
23 | - protected $step = ''; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var string|false Previous Step |
|
27 | - */ |
|
28 | - protected $previous_step = ''; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var string|false Next Step |
|
32 | - */ |
|
33 | - protected $next_step = ''; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var array All available steps for the setup wizard |
|
37 | - */ |
|
38 | - protected $steps = array(); |
|
39 | - |
|
40 | - /** |
|
41 | - * Class constructor. |
|
42 | - * |
|
43 | - * @since 2.4.0 |
|
44 | - */ |
|
45 | - public function __construct() { |
|
46 | - |
|
47 | - if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) { |
|
48 | - add_action( 'admin_menu', array( $this, 'add_menu' ) ); |
|
49 | - add_action( 'current_screen', array( $this, 'setup_wizard' ) ); |
|
50 | - add_action( 'admin_init', array( $this, 'remove_deprecated_functions' ) ); |
|
51 | - } |
|
52 | - |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Add admin menus/screens. |
|
57 | - * |
|
58 | - * @since 2.4.0 |
|
59 | - */ |
|
60 | - public function add_menu() { |
|
61 | - add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' ); |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Sets up the setup wizard. |
|
66 | - * |
|
67 | - * @since 2.4.0 |
|
68 | - */ |
|
69 | - public function setup_wizard() { |
|
70 | - |
|
71 | - if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) { |
|
72 | - $this->setup_globals(); |
|
73 | - $this->maybe_save_current_step(); |
|
74 | - $this->display_wizard(); |
|
75 | - exit; |
|
76 | - } |
|
77 | - |
|
78 | - } |
|
79 | - |
|
80 | - public function remove_deprecated_functions() { |
|
81 | - // removes deprecated warnings from page |
|
82 | - remove_action('admin_print_styles', 'print_emoji_styles'); |
|
83 | - remove_action( 'admin_head', 'wp_admin_bar_header' ); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Sets up class variables. |
|
88 | - * |
|
89 | - * @since 2.4.0 |
|
90 | - */ |
|
91 | - protected function setup_globals() { |
|
92 | - $this->steps = $this->get_setup_steps(); |
|
93 | - $this->step = $this->get_current_step(); |
|
94 | - $this->previous_step = $this->get_previous_step(); |
|
95 | - $this->next_step = $this->get_next_step(); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Saves the current step. |
|
100 | - * |
|
101 | - * @since 2.4.0 |
|
102 | - */ |
|
103 | - protected function maybe_save_current_step() { |
|
104 | - if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) { |
|
105 | - call_user_func( $this->steps[ $this->step ]['handler'], $this ); |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Returns the setup steps. |
|
111 | - * |
|
112 | - * @since 2.4.0 |
|
113 | - * @return array |
|
114 | - */ |
|
115 | - protected function get_setup_steps() { |
|
116 | - |
|
117 | - $steps = array( |
|
118 | - |
|
119 | - 'introduction' => array( |
|
120 | - 'name' => __( 'Introduction', 'invoicing' ), |
|
121 | - 'view' => array( $this, 'setup_introduction' ), |
|
122 | - 'handler' => '', |
|
123 | - ), |
|
124 | - |
|
125 | - 'business_details' => array( |
|
126 | - 'name' => __( 'Business Details', 'invoicing' ), |
|
127 | - 'view' => array( $this, 'setup_business' ), |
|
128 | - 'handler' => '', |
|
129 | - ), |
|
130 | - |
|
131 | - 'currency' => array( |
|
132 | - 'name' => __( 'Currency', 'invoicing' ), |
|
133 | - 'view' => array( $this, 'setup_currency' ), |
|
134 | - 'handler' => '', |
|
135 | - ), |
|
136 | - |
|
137 | - 'payments' => array( |
|
138 | - 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
139 | - 'view' => array( $this, 'setup_payments' ), |
|
140 | - 'handler' => array( $this, 'setup_payments_save' ), |
|
141 | - ), |
|
142 | - |
|
143 | - 'recommend' => array( |
|
144 | - 'name' => __( 'Recommend', 'invoicing' ), |
|
145 | - 'view' => array( $this, 'setup_recommend' ), |
|
146 | - 'handler' => '', |
|
147 | - ), |
|
148 | - |
|
149 | - 'next_steps' => array( |
|
150 | - 'name' => __( 'Get Paid', 'invoicing' ), |
|
151 | - 'view' => array( $this, 'setup_ready' ), |
|
152 | - 'handler' => '', |
|
153 | - ), |
|
154 | - |
|
155 | - ); |
|
156 | - |
|
157 | - return apply_filters( 'getpaid_setup_wizard_steps', $steps ); |
|
158 | - |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * Returns the current step. |
|
163 | - * |
|
164 | - * @since 2.4.0 |
|
165 | - * @return string |
|
166 | - */ |
|
167 | - protected function get_current_step() { |
|
168 | - $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : ''; |
|
169 | - return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) ); |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Returns the previous step. |
|
174 | - * |
|
175 | - * @since 2.4.0 |
|
176 | - * @return string|false |
|
177 | - */ |
|
178 | - protected function get_previous_step() { |
|
179 | - |
|
180 | - $previous = false; |
|
181 | - $current = $this->step; |
|
182 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
183 | - if ( $current === $step ) { |
|
184 | - return $previous; |
|
185 | - } |
|
186 | - |
|
187 | - $previous = $step; |
|
188 | - } |
|
189 | - |
|
190 | - return false; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Returns the next step. |
|
195 | - * |
|
196 | - * @since 2.4.0 |
|
197 | - * @return string|false |
|
198 | - */ |
|
199 | - protected function get_next_step() { |
|
200 | - |
|
201 | - $on_current = false; |
|
202 | - $current = $this->step; |
|
203 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
204 | - |
|
205 | - if ( $on_current ) { |
|
206 | - return $step; |
|
207 | - } |
|
208 | - |
|
209 | - if ( $current === $step ) { |
|
210 | - return $on_current = true; |
|
211 | - } |
|
20 | + /** |
|
21 | + * @var string Current Step |
|
22 | + */ |
|
23 | + protected $step = ''; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var string|false Previous Step |
|
27 | + */ |
|
28 | + protected $previous_step = ''; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var string|false Next Step |
|
32 | + */ |
|
33 | + protected $next_step = ''; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var array All available steps for the setup wizard |
|
37 | + */ |
|
38 | + protected $steps = array(); |
|
39 | + |
|
40 | + /** |
|
41 | + * Class constructor. |
|
42 | + * |
|
43 | + * @since 2.4.0 |
|
44 | + */ |
|
45 | + public function __construct() { |
|
46 | + |
|
47 | + if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) { |
|
48 | + add_action( 'admin_menu', array( $this, 'add_menu' ) ); |
|
49 | + add_action( 'current_screen', array( $this, 'setup_wizard' ) ); |
|
50 | + add_action( 'admin_init', array( $this, 'remove_deprecated_functions' ) ); |
|
51 | + } |
|
52 | + |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Add admin menus/screens. |
|
57 | + * |
|
58 | + * @since 2.4.0 |
|
59 | + */ |
|
60 | + public function add_menu() { |
|
61 | + add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' ); |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Sets up the setup wizard. |
|
66 | + * |
|
67 | + * @since 2.4.0 |
|
68 | + */ |
|
69 | + public function setup_wizard() { |
|
70 | + |
|
71 | + if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) { |
|
72 | + $this->setup_globals(); |
|
73 | + $this->maybe_save_current_step(); |
|
74 | + $this->display_wizard(); |
|
75 | + exit; |
|
76 | + } |
|
77 | + |
|
78 | + } |
|
79 | + |
|
80 | + public function remove_deprecated_functions() { |
|
81 | + // removes deprecated warnings from page |
|
82 | + remove_action('admin_print_styles', 'print_emoji_styles'); |
|
83 | + remove_action( 'admin_head', 'wp_admin_bar_header' ); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Sets up class variables. |
|
88 | + * |
|
89 | + * @since 2.4.0 |
|
90 | + */ |
|
91 | + protected function setup_globals() { |
|
92 | + $this->steps = $this->get_setup_steps(); |
|
93 | + $this->step = $this->get_current_step(); |
|
94 | + $this->previous_step = $this->get_previous_step(); |
|
95 | + $this->next_step = $this->get_next_step(); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Saves the current step. |
|
100 | + * |
|
101 | + * @since 2.4.0 |
|
102 | + */ |
|
103 | + protected function maybe_save_current_step() { |
|
104 | + if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) { |
|
105 | + call_user_func( $this->steps[ $this->step ]['handler'], $this ); |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Returns the setup steps. |
|
111 | + * |
|
112 | + * @since 2.4.0 |
|
113 | + * @return array |
|
114 | + */ |
|
115 | + protected function get_setup_steps() { |
|
116 | + |
|
117 | + $steps = array( |
|
118 | + |
|
119 | + 'introduction' => array( |
|
120 | + 'name' => __( 'Introduction', 'invoicing' ), |
|
121 | + 'view' => array( $this, 'setup_introduction' ), |
|
122 | + 'handler' => '', |
|
123 | + ), |
|
124 | + |
|
125 | + 'business_details' => array( |
|
126 | + 'name' => __( 'Business Details', 'invoicing' ), |
|
127 | + 'view' => array( $this, 'setup_business' ), |
|
128 | + 'handler' => '', |
|
129 | + ), |
|
130 | + |
|
131 | + 'currency' => array( |
|
132 | + 'name' => __( 'Currency', 'invoicing' ), |
|
133 | + 'view' => array( $this, 'setup_currency' ), |
|
134 | + 'handler' => '', |
|
135 | + ), |
|
136 | + |
|
137 | + 'payments' => array( |
|
138 | + 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
139 | + 'view' => array( $this, 'setup_payments' ), |
|
140 | + 'handler' => array( $this, 'setup_payments_save' ), |
|
141 | + ), |
|
142 | + |
|
143 | + 'recommend' => array( |
|
144 | + 'name' => __( 'Recommend', 'invoicing' ), |
|
145 | + 'view' => array( $this, 'setup_recommend' ), |
|
146 | + 'handler' => '', |
|
147 | + ), |
|
148 | + |
|
149 | + 'next_steps' => array( |
|
150 | + 'name' => __( 'Get Paid', 'invoicing' ), |
|
151 | + 'view' => array( $this, 'setup_ready' ), |
|
152 | + 'handler' => '', |
|
153 | + ), |
|
154 | + |
|
155 | + ); |
|
156 | + |
|
157 | + return apply_filters( 'getpaid_setup_wizard_steps', $steps ); |
|
158 | + |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * Returns the current step. |
|
163 | + * |
|
164 | + * @since 2.4.0 |
|
165 | + * @return string |
|
166 | + */ |
|
167 | + protected function get_current_step() { |
|
168 | + $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : ''; |
|
169 | + return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) ); |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Returns the previous step. |
|
174 | + * |
|
175 | + * @since 2.4.0 |
|
176 | + * @return string|false |
|
177 | + */ |
|
178 | + protected function get_previous_step() { |
|
179 | + |
|
180 | + $previous = false; |
|
181 | + $current = $this->step; |
|
182 | + foreach ( array_keys( $this->steps ) as $step ) { |
|
183 | + if ( $current === $step ) { |
|
184 | + return $previous; |
|
185 | + } |
|
186 | + |
|
187 | + $previous = $step; |
|
188 | + } |
|
189 | + |
|
190 | + return false; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Returns the next step. |
|
195 | + * |
|
196 | + * @since 2.4.0 |
|
197 | + * @return string|false |
|
198 | + */ |
|
199 | + protected function get_next_step() { |
|
200 | + |
|
201 | + $on_current = false; |
|
202 | + $current = $this->step; |
|
203 | + foreach ( array_keys( $this->steps ) as $step ) { |
|
204 | + |
|
205 | + if ( $on_current ) { |
|
206 | + return $step; |
|
207 | + } |
|
208 | + |
|
209 | + if ( $current === $step ) { |
|
210 | + return $on_current = true; |
|
211 | + } |
|
212 | 212 | } |
213 | 213 | |
214 | - return false; |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * Displays the setup wizard. |
|
219 | - * |
|
220 | - * @since 2.4.0 |
|
221 | - */ |
|
222 | - public function display_wizard() { |
|
223 | - $this->display_header(); |
|
224 | - $this->display_current_step(); |
|
225 | - $this->display_footer(); |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * Displays the Wizard Header. |
|
230 | - * |
|
231 | - * @since 2.0.0 |
|
232 | - */ |
|
233 | - public function display_header() { |
|
234 | - $steps = $this->steps; |
|
235 | - $current = $this->step; |
|
236 | - $next_step = $this->next_step; |
|
237 | - array_shift( $steps ); |
|
238 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php'; |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * Displays the content for the current step. |
|
243 | - * |
|
244 | - * @since 2.4.0 |
|
245 | - */ |
|
246 | - public function display_current_step() { |
|
247 | - ?> |
|
214 | + return false; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * Displays the setup wizard. |
|
219 | + * |
|
220 | + * @since 2.4.0 |
|
221 | + */ |
|
222 | + public function display_wizard() { |
|
223 | + $this->display_header(); |
|
224 | + $this->display_current_step(); |
|
225 | + $this->display_footer(); |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * Displays the Wizard Header. |
|
230 | + * |
|
231 | + * @since 2.0.0 |
|
232 | + */ |
|
233 | + public function display_header() { |
|
234 | + $steps = $this->steps; |
|
235 | + $current = $this->step; |
|
236 | + $next_step = $this->next_step; |
|
237 | + array_shift( $steps ); |
|
238 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php'; |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * Displays the content for the current step. |
|
243 | + * |
|
244 | + * @since 2.4.0 |
|
245 | + */ |
|
246 | + public function display_current_step() { |
|
247 | + ?> |
|
248 | 248 | <div class="gp-setup-content rowx mw-100 text-center mb-3"> |
249 | 249 | <div class="col-12 col-md-5 m-auto"> |
250 | 250 | <?php call_user_func( $this->steps[ $this->step ]['view'], $this ); ?> |
251 | 251 | </div> |
252 | 252 | </div> |
253 | 253 | <?php |
254 | - } |
|
255 | - |
|
256 | - /** |
|
257 | - * Setup Wizard Footer. |
|
258 | - * |
|
259 | - * @since 2.4.0 |
|
260 | - */ |
|
261 | - public function display_footer() { |
|
262 | - |
|
263 | - if ( isset( $_GET['step'] ) ) { |
|
264 | - $label = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' ); |
|
265 | - |
|
266 | - echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . esc_url( $this->get_next_step_link() ) . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . esc_html( $label ) . '</a></p>'; |
|
267 | - } |
|
268 | - |
|
269 | - echo '</body></html>'; |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * Introduction step. |
|
274 | - * |
|
275 | - * @since 2.0.0 |
|
276 | - */ |
|
277 | - public function setup_introduction() { |
|
278 | - $next_url = $this->get_next_step_link(); |
|
279 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php'; |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * Get the URL for the next step's screen. |
|
284 | - * |
|
285 | - * @param string step slug (default: current step) |
|
286 | - * |
|
287 | - * @return string URL for next step if a next step exists. |
|
288 | - * Admin URL if it's the last step. |
|
289 | - * Empty string on failure. |
|
290 | - * @since 3.0.0 |
|
291 | - */ |
|
292 | - public function get_next_step_link( $step = '' ) { |
|
293 | - if ( ! $step ) { |
|
294 | - $step = $this->step; |
|
295 | - } |
|
296 | - |
|
297 | - $keys = array_keys( $this->steps ); |
|
298 | - if ( end( $keys ) === $step ) { |
|
299 | - return admin_url(); |
|
300 | - } |
|
301 | - |
|
302 | - $step_index = array_search( $step, $keys ); |
|
303 | - if ( false === $step_index ) { |
|
304 | - return ''; |
|
305 | - } |
|
306 | - |
|
307 | - return remove_query_arg( 'settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] ) ); |
|
308 | - } |
|
309 | - |
|
310 | - /** |
|
311 | - * Setup maps api. |
|
312 | - * |
|
313 | - * @since 2.0.0 |
|
314 | - */ |
|
315 | - public function setup_business() { |
|
316 | - $next_url = $this->get_next_step_link(); |
|
317 | - $wizard = $this; |
|
318 | - $page = 'wpinv_settings_general_main'; |
|
319 | - $section = 'wpinv_settings_general_main'; |
|
320 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * Default Location settings. |
|
325 | - * |
|
326 | - * @since 2.0.0 |
|
327 | - */ |
|
328 | - public function setup_currency() { |
|
329 | - $next_url = $this->get_next_step_link(); |
|
330 | - $wizard = $this; |
|
331 | - $page = 'wpinv_settings_general_currency_section'; |
|
332 | - $section = 'wpinv_settings_general_currency_section'; |
|
333 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
334 | - } |
|
335 | - |
|
336 | - /** |
|
337 | - * Installation of recommended plugins. |
|
338 | - * |
|
339 | - * @since 1.0.0 |
|
340 | - */ |
|
341 | - public function setup_recommend() { |
|
342 | - $next_url = $this->get_next_step_link(); |
|
343 | - $recommended_plugins = self::get_recommend_wp_plugins(); |
|
344 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php'; |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * A list of recommended wp.org plugins. |
|
349 | - * @return array |
|
350 | - */ |
|
351 | - public static function get_recommend_wp_plugins() { |
|
352 | - return array( |
|
353 | - 'ayecode-connect' => array( |
|
354 | - 'file' => 'ayecode-connect/ayecode-connect.php', |
|
355 | - 'url' => 'https://wordpress.org/plugins/ayecode-connect/', |
|
356 | - 'slug' => 'ayecode-connect', |
|
357 | - 'name' => 'AyeCode Connect', |
|
358 | - 'desc' => __( 'Documentation and Support from within your WordPress admin.', 'invoicing' ), |
|
359 | - ), |
|
360 | - 'invoicing-quotes' => array( |
|
361 | - 'file' => 'invoicing-quotes/wpinv-quote.php', |
|
362 | - 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
|
363 | - 'slug' => 'invoicing-quotes', |
|
364 | - 'name' => 'Customer Quotes', |
|
365 | - 'desc' => __( 'Create & Send Quotes to Customers and have them accept and pay.', 'invoicing' ), |
|
366 | - ), |
|
367 | - 'userswp' => array( |
|
368 | - 'file' => 'userswp/userswp.php', |
|
369 | - 'url' => 'https://wordpress.org/plugins/userswp/', |
|
370 | - 'slug' => 'userswp', |
|
371 | - 'name' => 'UsersWP', |
|
372 | - 'desc' => __( 'Frontend user login and registration as well as slick profile pages.', 'invoicing' ), |
|
373 | - ), |
|
374 | - ); |
|
375 | - } |
|
376 | - |
|
377 | - /** |
|
378 | - * Dummy Data setup. |
|
379 | - * |
|
380 | - * @since 2.4.0 |
|
381 | - */ |
|
382 | - public function setup_payments() { |
|
383 | - $next_url = $this->get_next_step_link(); |
|
384 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php'; |
|
385 | - } |
|
386 | - |
|
387 | - /** |
|
388 | - * Dummy data save. |
|
389 | - * |
|
390 | - * This is done via ajax so we just pass onto the next step. |
|
391 | - * |
|
392 | - * @since 2.0.0 |
|
393 | - */ |
|
394 | - public function setup_payments_save() { |
|
395 | - check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); |
|
396 | - wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) ); |
|
397 | - |
|
398 | - if ( ! empty( $_POST['paypal-email'] ) ) { |
|
399 | - wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) ); |
|
400 | - wpinv_update_option( 'paypal_active', 1 ); |
|
401 | - wpinv_update_option( 'paypal_sandbox', 0 ); |
|
402 | - } |
|
403 | - |
|
404 | - wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
|
405 | - exit; |
|
406 | - } |
|
407 | - |
|
408 | - /** |
|
409 | - * Final step. |
|
410 | - * |
|
411 | - * @since 2.0.0 |
|
412 | - */ |
|
413 | - public function setup_ready() { |
|
414 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php'; |
|
415 | - } |
|
254 | + } |
|
255 | + |
|
256 | + /** |
|
257 | + * Setup Wizard Footer. |
|
258 | + * |
|
259 | + * @since 2.4.0 |
|
260 | + */ |
|
261 | + public function display_footer() { |
|
262 | + |
|
263 | + if ( isset( $_GET['step'] ) ) { |
|
264 | + $label = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' ); |
|
265 | + |
|
266 | + echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . esc_url( $this->get_next_step_link() ) . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . esc_html( $label ) . '</a></p>'; |
|
267 | + } |
|
268 | + |
|
269 | + echo '</body></html>'; |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * Introduction step. |
|
274 | + * |
|
275 | + * @since 2.0.0 |
|
276 | + */ |
|
277 | + public function setup_introduction() { |
|
278 | + $next_url = $this->get_next_step_link(); |
|
279 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php'; |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * Get the URL for the next step's screen. |
|
284 | + * |
|
285 | + * @param string step slug (default: current step) |
|
286 | + * |
|
287 | + * @return string URL for next step if a next step exists. |
|
288 | + * Admin URL if it's the last step. |
|
289 | + * Empty string on failure. |
|
290 | + * @since 3.0.0 |
|
291 | + */ |
|
292 | + public function get_next_step_link( $step = '' ) { |
|
293 | + if ( ! $step ) { |
|
294 | + $step = $this->step; |
|
295 | + } |
|
296 | + |
|
297 | + $keys = array_keys( $this->steps ); |
|
298 | + if ( end( $keys ) === $step ) { |
|
299 | + return admin_url(); |
|
300 | + } |
|
301 | + |
|
302 | + $step_index = array_search( $step, $keys ); |
|
303 | + if ( false === $step_index ) { |
|
304 | + return ''; |
|
305 | + } |
|
306 | + |
|
307 | + return remove_query_arg( 'settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] ) ); |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * Setup maps api. |
|
312 | + * |
|
313 | + * @since 2.0.0 |
|
314 | + */ |
|
315 | + public function setup_business() { |
|
316 | + $next_url = $this->get_next_step_link(); |
|
317 | + $wizard = $this; |
|
318 | + $page = 'wpinv_settings_general_main'; |
|
319 | + $section = 'wpinv_settings_general_main'; |
|
320 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * Default Location settings. |
|
325 | + * |
|
326 | + * @since 2.0.0 |
|
327 | + */ |
|
328 | + public function setup_currency() { |
|
329 | + $next_url = $this->get_next_step_link(); |
|
330 | + $wizard = $this; |
|
331 | + $page = 'wpinv_settings_general_currency_section'; |
|
332 | + $section = 'wpinv_settings_general_currency_section'; |
|
333 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
334 | + } |
|
335 | + |
|
336 | + /** |
|
337 | + * Installation of recommended plugins. |
|
338 | + * |
|
339 | + * @since 1.0.0 |
|
340 | + */ |
|
341 | + public function setup_recommend() { |
|
342 | + $next_url = $this->get_next_step_link(); |
|
343 | + $recommended_plugins = self::get_recommend_wp_plugins(); |
|
344 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php'; |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * A list of recommended wp.org plugins. |
|
349 | + * @return array |
|
350 | + */ |
|
351 | + public static function get_recommend_wp_plugins() { |
|
352 | + return array( |
|
353 | + 'ayecode-connect' => array( |
|
354 | + 'file' => 'ayecode-connect/ayecode-connect.php', |
|
355 | + 'url' => 'https://wordpress.org/plugins/ayecode-connect/', |
|
356 | + 'slug' => 'ayecode-connect', |
|
357 | + 'name' => 'AyeCode Connect', |
|
358 | + 'desc' => __( 'Documentation and Support from within your WordPress admin.', 'invoicing' ), |
|
359 | + ), |
|
360 | + 'invoicing-quotes' => array( |
|
361 | + 'file' => 'invoicing-quotes/wpinv-quote.php', |
|
362 | + 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
|
363 | + 'slug' => 'invoicing-quotes', |
|
364 | + 'name' => 'Customer Quotes', |
|
365 | + 'desc' => __( 'Create & Send Quotes to Customers and have them accept and pay.', 'invoicing' ), |
|
366 | + ), |
|
367 | + 'userswp' => array( |
|
368 | + 'file' => 'userswp/userswp.php', |
|
369 | + 'url' => 'https://wordpress.org/plugins/userswp/', |
|
370 | + 'slug' => 'userswp', |
|
371 | + 'name' => 'UsersWP', |
|
372 | + 'desc' => __( 'Frontend user login and registration as well as slick profile pages.', 'invoicing' ), |
|
373 | + ), |
|
374 | + ); |
|
375 | + } |
|
376 | + |
|
377 | + /** |
|
378 | + * Dummy Data setup. |
|
379 | + * |
|
380 | + * @since 2.4.0 |
|
381 | + */ |
|
382 | + public function setup_payments() { |
|
383 | + $next_url = $this->get_next_step_link(); |
|
384 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php'; |
|
385 | + } |
|
386 | + |
|
387 | + /** |
|
388 | + * Dummy data save. |
|
389 | + * |
|
390 | + * This is done via ajax so we just pass onto the next step. |
|
391 | + * |
|
392 | + * @since 2.0.0 |
|
393 | + */ |
|
394 | + public function setup_payments_save() { |
|
395 | + check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); |
|
396 | + wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) ); |
|
397 | + |
|
398 | + if ( ! empty( $_POST['paypal-email'] ) ) { |
|
399 | + wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) ); |
|
400 | + wpinv_update_option( 'paypal_active', 1 ); |
|
401 | + wpinv_update_option( 'paypal_sandbox', 0 ); |
|
402 | + } |
|
403 | + |
|
404 | + wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
|
405 | + exit; |
|
406 | + } |
|
407 | + |
|
408 | + /** |
|
409 | + * Final step. |
|
410 | + * |
|
411 | + * @since 2.0.0 |
|
412 | + */ |
|
413 | + public function setup_ready() { |
|
414 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php'; |
|
415 | + } |
|
416 | 416 | |
417 | 417 | } |
418 | 418 |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @version 2.4.0 |
11 | 11 | * @info GetPaid Setup Wizard. |
12 | 12 | */ |
13 | -defined( 'ABSPATH' ) || exit; |
|
13 | +defined('ABSPATH') || exit; |
|
14 | 14 | |
15 | 15 | /** |
16 | 16 | * GetPaid_Admin_Setup_Wizard class. |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public function __construct() { |
46 | 46 | |
47 | - if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) { |
|
48 | - add_action( 'admin_menu', array( $this, 'add_menu' ) ); |
|
49 | - add_action( 'current_screen', array( $this, 'setup_wizard' ) ); |
|
50 | - add_action( 'admin_init', array( $this, 'remove_deprecated_functions' ) ); |
|
47 | + if (apply_filters('getpaid_enable_setup_wizard', true) && wpinv_current_user_can_manage_invoicing()) { |
|
48 | + add_action('admin_menu', array($this, 'add_menu')); |
|
49 | + add_action('current_screen', array($this, 'setup_wizard')); |
|
50 | + add_action('admin_init', array($this, 'remove_deprecated_functions')); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @since 2.4.0 |
59 | 59 | */ |
60 | 60 | public function add_menu() { |
61 | - add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' ); |
|
61 | + add_dashboard_page('', '', wpinv_get_capability(), 'gp-setup', ''); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function setup_wizard() { |
70 | 70 | |
71 | - if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) { |
|
71 | + if (isset($_GET['page']) && 'gp-setup' === $_GET['page']) { |
|
72 | 72 | $this->setup_globals(); |
73 | 73 | $this->maybe_save_current_step(); |
74 | 74 | $this->display_wizard(); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | public function remove_deprecated_functions() { |
81 | 81 | // removes deprecated warnings from page |
82 | 82 | remove_action('admin_print_styles', 'print_emoji_styles'); |
83 | - remove_action( 'admin_head', 'wp_admin_bar_header' ); |
|
83 | + remove_action('admin_head', 'wp_admin_bar_header'); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | * @since 2.4.0 |
102 | 102 | */ |
103 | 103 | protected function maybe_save_current_step() { |
104 | - if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) { |
|
105 | - call_user_func( $this->steps[ $this->step ]['handler'], $this ); |
|
104 | + if (!empty($_POST['save_step']) && is_callable($this->steps[$this->step]['handler'])) { |
|
105 | + call_user_func($this->steps[$this->step]['handler'], $this); |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
@@ -117,44 +117,44 @@ discard block |
||
117 | 117 | $steps = array( |
118 | 118 | |
119 | 119 | 'introduction' => array( |
120 | - 'name' => __( 'Introduction', 'invoicing' ), |
|
121 | - 'view' => array( $this, 'setup_introduction' ), |
|
120 | + 'name' => __('Introduction', 'invoicing'), |
|
121 | + 'view' => array($this, 'setup_introduction'), |
|
122 | 122 | 'handler' => '', |
123 | 123 | ), |
124 | 124 | |
125 | 125 | 'business_details' => array( |
126 | - 'name' => __( 'Business Details', 'invoicing' ), |
|
127 | - 'view' => array( $this, 'setup_business' ), |
|
126 | + 'name' => __('Business Details', 'invoicing'), |
|
127 | + 'view' => array($this, 'setup_business'), |
|
128 | 128 | 'handler' => '', |
129 | 129 | ), |
130 | 130 | |
131 | 131 | 'currency' => array( |
132 | - 'name' => __( 'Currency', 'invoicing' ), |
|
133 | - 'view' => array( $this, 'setup_currency' ), |
|
132 | + 'name' => __('Currency', 'invoicing'), |
|
133 | + 'view' => array($this, 'setup_currency'), |
|
134 | 134 | 'handler' => '', |
135 | 135 | ), |
136 | 136 | |
137 | 137 | 'payments' => array( |
138 | - 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
139 | - 'view' => array( $this, 'setup_payments' ), |
|
140 | - 'handler' => array( $this, 'setup_payments_save' ), |
|
138 | + 'name' => __('Payment Gateways', 'invoicing'), |
|
139 | + 'view' => array($this, 'setup_payments'), |
|
140 | + 'handler' => array($this, 'setup_payments_save'), |
|
141 | 141 | ), |
142 | 142 | |
143 | 143 | 'recommend' => array( |
144 | - 'name' => __( 'Recommend', 'invoicing' ), |
|
145 | - 'view' => array( $this, 'setup_recommend' ), |
|
144 | + 'name' => __('Recommend', 'invoicing'), |
|
145 | + 'view' => array($this, 'setup_recommend'), |
|
146 | 146 | 'handler' => '', |
147 | 147 | ), |
148 | 148 | |
149 | 149 | 'next_steps' => array( |
150 | - 'name' => __( 'Get Paid', 'invoicing' ), |
|
151 | - 'view' => array( $this, 'setup_ready' ), |
|
150 | + 'name' => __('Get Paid', 'invoicing'), |
|
151 | + 'view' => array($this, 'setup_ready'), |
|
152 | 152 | 'handler' => '', |
153 | 153 | ), |
154 | 154 | |
155 | 155 | ); |
156 | 156 | |
157 | - return apply_filters( 'getpaid_setup_wizard_steps', $steps ); |
|
157 | + return apply_filters('getpaid_setup_wizard_steps', $steps); |
|
158 | 158 | |
159 | 159 | } |
160 | 160 | |
@@ -165,8 +165,8 @@ discard block |
||
165 | 165 | * @return string |
166 | 166 | */ |
167 | 167 | protected function get_current_step() { |
168 | - $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : ''; |
|
169 | - return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) ); |
|
168 | + $step = isset($_GET['step']) ? sanitize_key($_GET['step']) : ''; |
|
169 | + return !empty($step) && in_array($step, array_keys($this->steps)) ? $step : current(array_keys($this->steps)); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
@@ -179,8 +179,8 @@ discard block |
||
179 | 179 | |
180 | 180 | $previous = false; |
181 | 181 | $current = $this->step; |
182 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
183 | - if ( $current === $step ) { |
|
182 | + foreach (array_keys($this->steps) as $step) { |
|
183 | + if ($current === $step) { |
|
184 | 184 | return $previous; |
185 | 185 | } |
186 | 186 | |
@@ -200,13 +200,13 @@ discard block |
||
200 | 200 | |
201 | 201 | $on_current = false; |
202 | 202 | $current = $this->step; |
203 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
203 | + foreach (array_keys($this->steps) as $step) { |
|
204 | 204 | |
205 | - if ( $on_current ) { |
|
205 | + if ($on_current) { |
|
206 | 206 | return $step; |
207 | 207 | } |
208 | 208 | |
209 | - if ( $current === $step ) { |
|
209 | + if ($current === $step) { |
|
210 | 210 | return $on_current = true; |
211 | 211 | } |
212 | 212 | } |
@@ -234,8 +234,8 @@ discard block |
||
234 | 234 | $steps = $this->steps; |
235 | 235 | $current = $this->step; |
236 | 236 | $next_step = $this->next_step; |
237 | - array_shift( $steps ); |
|
238 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php'; |
|
237 | + array_shift($steps); |
|
238 | + include plugin_dir_path(__FILE__) . 'views/wizard-header.php'; |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | /** |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | ?> |
248 | 248 | <div class="gp-setup-content rowx mw-100 text-center mb-3"> |
249 | 249 | <div class="col-12 col-md-5 m-auto"> |
250 | - <?php call_user_func( $this->steps[ $this->step ]['view'], $this ); ?> |
|
250 | + <?php call_user_func($this->steps[$this->step]['view'], $this); ?> |
|
251 | 251 | </div> |
252 | 252 | </div> |
253 | 253 | <?php |
@@ -260,10 +260,10 @@ discard block |
||
260 | 260 | */ |
261 | 261 | public function display_footer() { |
262 | 262 | |
263 | - if ( isset( $_GET['step'] ) ) { |
|
264 | - $label = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' ); |
|
263 | + if (isset($_GET['step'])) { |
|
264 | + $label = $this->step == 'next_steps' ? __('Return to the WordPress Dashboard', 'invoicing') : __('Skip this step', 'invoicing'); |
|
265 | 265 | |
266 | - echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . esc_url( $this->get_next_step_link() ) . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . esc_html( $label ) . '</a></p>'; |
|
266 | + echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . esc_url($this->get_next_step_link()) . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . esc_html($label) . '</a></p>'; |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | echo '</body></html>'; |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | */ |
277 | 277 | public function setup_introduction() { |
278 | 278 | $next_url = $this->get_next_step_link(); |
279 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php'; |
|
279 | + include plugin_dir_path(__FILE__) . 'views/wizard-introduction.php'; |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | /** |
@@ -289,22 +289,22 @@ discard block |
||
289 | 289 | * Empty string on failure. |
290 | 290 | * @since 3.0.0 |
291 | 291 | */ |
292 | - public function get_next_step_link( $step = '' ) { |
|
293 | - if ( ! $step ) { |
|
292 | + public function get_next_step_link($step = '') { |
|
293 | + if (!$step) { |
|
294 | 294 | $step = $this->step; |
295 | 295 | } |
296 | 296 | |
297 | - $keys = array_keys( $this->steps ); |
|
298 | - if ( end( $keys ) === $step ) { |
|
297 | + $keys = array_keys($this->steps); |
|
298 | + if (end($keys) === $step) { |
|
299 | 299 | return admin_url(); |
300 | 300 | } |
301 | 301 | |
302 | - $step_index = array_search( $step, $keys ); |
|
303 | - if ( false === $step_index ) { |
|
302 | + $step_index = array_search($step, $keys); |
|
303 | + if (false === $step_index) { |
|
304 | 304 | return ''; |
305 | 305 | } |
306 | 306 | |
307 | - return remove_query_arg( 'settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] ) ); |
|
307 | + return remove_query_arg('settings-updated', add_query_arg('step', $keys[$step_index + 1])); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | $wizard = $this; |
318 | 318 | $page = 'wpinv_settings_general_main'; |
319 | 319 | $section = 'wpinv_settings_general_main'; |
320 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
320 | + include plugin_dir_path(__FILE__) . 'views/wizard-settings.php'; |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | /** |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | $wizard = $this; |
331 | 331 | $page = 'wpinv_settings_general_currency_section'; |
332 | 332 | $section = 'wpinv_settings_general_currency_section'; |
333 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
333 | + include plugin_dir_path(__FILE__) . 'views/wizard-settings.php'; |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | public function setup_recommend() { |
342 | 342 | $next_url = $this->get_next_step_link(); |
343 | 343 | $recommended_plugins = self::get_recommend_wp_plugins(); |
344 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php'; |
|
344 | + include plugin_dir_path(__FILE__) . 'views/wizard-plugins.php'; |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | /** |
@@ -355,21 +355,21 @@ discard block |
||
355 | 355 | 'url' => 'https://wordpress.org/plugins/ayecode-connect/', |
356 | 356 | 'slug' => 'ayecode-connect', |
357 | 357 | 'name' => 'AyeCode Connect', |
358 | - 'desc' => __( 'Documentation and Support from within your WordPress admin.', 'invoicing' ), |
|
358 | + 'desc' => __('Documentation and Support from within your WordPress admin.', 'invoicing'), |
|
359 | 359 | ), |
360 | 360 | 'invoicing-quotes' => array( |
361 | 361 | 'file' => 'invoicing-quotes/wpinv-quote.php', |
362 | 362 | 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
363 | 363 | 'slug' => 'invoicing-quotes', |
364 | 364 | 'name' => 'Customer Quotes', |
365 | - 'desc' => __( 'Create & Send Quotes to Customers and have them accept and pay.', 'invoicing' ), |
|
365 | + 'desc' => __('Create & Send Quotes to Customers and have them accept and pay.', 'invoicing'), |
|
366 | 366 | ), |
367 | 367 | 'userswp' => array( |
368 | 368 | 'file' => 'userswp/userswp.php', |
369 | 369 | 'url' => 'https://wordpress.org/plugins/userswp/', |
370 | 370 | 'slug' => 'userswp', |
371 | 371 | 'name' => 'UsersWP', |
372 | - 'desc' => __( 'Frontend user login and registration as well as slick profile pages.', 'invoicing' ), |
|
372 | + 'desc' => __('Frontend user login and registration as well as slick profile pages.', 'invoicing'), |
|
373 | 373 | ), |
374 | 374 | ); |
375 | 375 | } |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | */ |
382 | 382 | public function setup_payments() { |
383 | 383 | $next_url = $this->get_next_step_link(); |
384 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php'; |
|
384 | + include plugin_dir_path(__FILE__) . 'views/wizard-gateways.php'; |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | /** |
@@ -392,16 +392,16 @@ discard block |
||
392 | 392 | * @since 2.0.0 |
393 | 393 | */ |
394 | 394 | public function setup_payments_save() { |
395 | - check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); |
|
396 | - wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) ); |
|
395 | + check_admin_referer('getpaid-setup-wizard', 'getpaid-setup-wizard'); |
|
396 | + wpinv_update_option('manual_active', !empty($_POST['enable-manual-gateway'])); |
|
397 | 397 | |
398 | - if ( ! empty( $_POST['paypal-email'] ) ) { |
|
399 | - wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) ); |
|
400 | - wpinv_update_option( 'paypal_active', 1 ); |
|
401 | - wpinv_update_option( 'paypal_sandbox', 0 ); |
|
398 | + if (!empty($_POST['paypal-email'])) { |
|
399 | + wpinv_update_option('paypal_email', sanitize_email($_POST['paypal-email'])); |
|
400 | + wpinv_update_option('paypal_active', 1); |
|
401 | + wpinv_update_option('paypal_sandbox', 0); |
|
402 | 402 | } |
403 | 403 | |
404 | - wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
|
404 | + wp_redirect(esc_url_raw($this->get_next_step_link())); |
|
405 | 405 | exit; |
406 | 406 | } |
407 | 407 | |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | * @since 2.0.0 |
412 | 412 | */ |
413 | 413 | public function setup_ready() { |
414 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php'; |
|
414 | + include plugin_dir_path(__FILE__) . 'views/wizard-thank-you.php'; |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | } |