@@ -13,58 +13,58 @@ discard block |
||
13 | 13 | class GetPaid_Authorize_Net_Gateway extends GetPaid_Authorize_Net_Legacy_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'authorizenet'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | 34 | public $order = 4; |
35 | 35 | |
36 | 36 | /** |
37 | - * Endpoint for requests from Authorize.net. |
|
38 | - * |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - protected $notify_url; |
|
42 | - |
|
43 | - /** |
|
44 | - * Endpoint for requests to Authorize.net. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
37 | + * Endpoint for requests from Authorize.net. |
|
38 | + * |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + protected $notify_url; |
|
42 | + |
|
43 | + /** |
|
44 | + * Endpoint for requests to Authorize.net. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | 48 | protected $endpoint; |
49 | 49 | |
50 | 50 | /** |
51 | - * Currencies this gateway is allowed for. |
|
52 | - * |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
51 | + * Currencies this gateway is allowed for. |
|
52 | + * |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
56 | 56 | |
57 | 57 | /** |
58 | - * URL to view a transaction. |
|
59 | - * |
|
60 | - * @var string |
|
61 | - */ |
|
58 | + * URL to view a transaction. |
|
59 | + * |
|
60 | + * @var string |
|
61 | + */ |
|
62 | 62 | public $view_transaction_url = 'https://{sandbox}authorize.net/ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=%s'; |
63 | 63 | |
64 | 64 | /** |
65 | - * Class constructor. |
|
66 | - */ |
|
67 | - public function __construct() { |
|
65 | + * Class constructor. |
|
66 | + */ |
|
67 | + public function __construct() { |
|
68 | 68 | |
69 | 69 | $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
70 | 70 | $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
@@ -76,11 +76,11 @@ discard block |
||
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | - * Displays the payment method select field. |
|
80 | - * |
|
81 | - * @param int $invoice_id 0 or invoice id. |
|
82 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
83 | - */ |
|
79 | + * Displays the payment method select field. |
|
80 | + * |
|
81 | + * @param int $invoice_id 0 or invoice id. |
|
82 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
83 | + */ |
|
84 | 84 | public function payment_fields( $invoice_id, $form ) { |
85 | 85 | |
86 | 86 | // Let the user select a payment method. |
@@ -91,16 +91,16 @@ discard block |
||
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
94 | - * Creates a customer profile. |
|
95 | - * |
|
96 | - * |
|
97 | - * @param WPInv_Invoice $invoice Invoice. |
|
94 | + * Creates a customer profile. |
|
95 | + * |
|
96 | + * |
|
97 | + * @param WPInv_Invoice $invoice Invoice. |
|
98 | 98 | * @param array $submission_data Posted checkout fields. |
99 | 99 | * @param bool $save Whether or not to save the payment as a token. |
100 | 100 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
101 | - * @return string|WP_Error Payment profile id. |
|
102 | - */ |
|
103 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
101 | + * @return string|WP_Error Payment profile id. |
|
102 | + */ |
|
103 | + public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
104 | 104 | |
105 | 105 | // Remove non-digits from the number |
106 | 106 | $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -175,14 +175,14 @@ discard block |
||
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
178 | - * Retrieves a customer profile. |
|
179 | - * |
|
180 | - * |
|
181 | - * @param string $profile_id profile id. |
|
182 | - * @return string|WP_Error Profile id. |
|
178 | + * Retrieves a customer profile. |
|
179 | + * |
|
180 | + * |
|
181 | + * @param string $profile_id profile id. |
|
182 | + * @return string|WP_Error Profile id. |
|
183 | 183 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
184 | - */ |
|
185 | - public function get_customer_profile( $profile_id ) { |
|
184 | + */ |
|
185 | + public function get_customer_profile( $profile_id ) { |
|
186 | 186 | |
187 | 187 | // Generate args. |
188 | 188 | $args = array( |
@@ -197,17 +197,17 @@ discard block |
||
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
200 | - * Creates a customer profile. |
|
201 | - * |
|
202 | - * |
|
200 | + * Creates a customer profile. |
|
201 | + * |
|
202 | + * |
|
203 | 203 | * @param string $profile_id profile id. |
204 | - * @param WPInv_Invoice $invoice Invoice. |
|
204 | + * @param WPInv_Invoice $invoice Invoice. |
|
205 | 205 | * @param array $submission_data Posted checkout fields. |
206 | 206 | * @param bool $save Whether or not to save the payment as a token. |
207 | 207 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
208 | - * @return string|WP_Error Profile id. |
|
209 | - */ |
|
210 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
208 | + * @return string|WP_Error Profile id. |
|
209 | + */ |
|
210 | + public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
211 | 211 | |
212 | 212 | // Remove non-digits from the number |
213 | 213 | $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -282,13 +282,13 @@ discard block |
||
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
285 | - * Retrieves payment details from cache. |
|
286 | - * |
|
287 | - * |
|
285 | + * Retrieves payment details from cache. |
|
286 | + * |
|
287 | + * |
|
288 | 288 | * @param array $payment_details. |
289 | - * @return array|false Profile id. |
|
290 | - */ |
|
291 | - public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
289 | + * @return array|false Profile id. |
|
290 | + */ |
|
291 | + public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
292 | 292 | |
293 | 293 | $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
294 | 294 | $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
@@ -313,13 +313,13 @@ discard block |
||
313 | 313 | } |
314 | 314 | |
315 | 315 | /** |
316 | - * Securely adds payment details to cache. |
|
317 | - * |
|
318 | - * |
|
316 | + * Securely adds payment details to cache. |
|
317 | + * |
|
318 | + * |
|
319 | 319 | * @param array $payment_details. |
320 | 320 | * @param string $payment_profile_id. |
321 | - */ |
|
322 | - public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
321 | + */ |
|
322 | + public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
323 | 323 | |
324 | 324 | $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
325 | 325 | $cached_information = is_array( $cached_information ) ? $cached_information : array(); |
@@ -331,15 +331,15 @@ discard block |
||
331 | 331 | } |
332 | 332 | |
333 | 333 | /** |
334 | - * Retrieves a customer payment profile. |
|
335 | - * |
|
336 | - * |
|
337 | - * @param string $customer_profile_id customer profile id. |
|
334 | + * Retrieves a customer payment profile. |
|
335 | + * |
|
336 | + * |
|
337 | + * @param string $customer_profile_id customer profile id. |
|
338 | 338 | * @param string $payment_profile_id payment profile id. |
339 | - * @return string|WP_Error Profile id. |
|
339 | + * @return string|WP_Error Profile id. |
|
340 | 340 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
341 | - */ |
|
342 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
341 | + */ |
|
342 | + public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
343 | 343 | |
344 | 344 | // Generate args. |
345 | 345 | $args = array( |
@@ -355,15 +355,15 @@ discard block |
||
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
358 | - * Charges a customer payment profile. |
|
359 | - * |
|
358 | + * Charges a customer payment profile. |
|
359 | + * |
|
360 | 360 | * @param string $customer_profile_id customer profile id. |
361 | 361 | * @param string $payment_profile_id payment profile id. |
362 | - * @param WPInv_Invoice $invoice Invoice. |
|
362 | + * @param WPInv_Invoice $invoice Invoice. |
|
363 | 363 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
364 | - * @return WP_Error|object |
|
365 | - */ |
|
366 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
364 | + * @return WP_Error|object |
|
365 | + */ |
|
366 | + public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
367 | 367 | |
368 | 368 | // Generate args. |
369 | 369 | $args = array( |
@@ -409,41 +409,41 @@ discard block |
||
409 | 409 | } |
410 | 410 | |
411 | 411 | /** |
412 | - * Processes a customer charge. |
|
413 | - * |
|
412 | + * Processes a customer charge. |
|
413 | + * |
|
414 | 414 | * @param stdClass $result Api response. |
415 | - * @param WPInv_Invoice $invoice Invoice. |
|
416 | - */ |
|
417 | - public function process_charge_response( $result, $invoice ) { |
|
415 | + * @param WPInv_Invoice $invoice Invoice. |
|
416 | + */ |
|
417 | + public function process_charge_response( $result, $invoice ) { |
|
418 | 418 | |
419 | 419 | wpinv_clear_errors(); |
420 | - $response_code = (int) $result->transactionResponse->responseCode; |
|
420 | + $response_code = (int) $result->transactionResponse->responseCode; |
|
421 | 421 | |
422 | - // Succeeded. |
|
423 | - if ( 1 == $response_code || 4 == $response_code ) { |
|
422 | + // Succeeded. |
|
423 | + if ( 1 == $response_code || 4 == $response_code ) { |
|
424 | 424 | |
425 | - // Maybe set a transaction id. |
|
426 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
427 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
428 | - } |
|
425 | + // Maybe set a transaction id. |
|
426 | + if ( ! empty( $result->transactionResponse->transId ) ) { |
|
427 | + $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
428 | + } |
|
429 | 429 | |
430 | - $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
430 | + $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
431 | 431 | |
432 | - if ( 1 == $response_code ) { |
|
433 | - return $invoice->mark_paid(); |
|
434 | - } |
|
432 | + if ( 1 == $response_code ) { |
|
433 | + return $invoice->mark_paid(); |
|
434 | + } |
|
435 | 435 | |
436 | - $invoice->set_status( 'wpi-onhold' ); |
|
437 | - $invoice->add_note( |
|
436 | + $invoice->set_status( 'wpi-onhold' ); |
|
437 | + $invoice->add_note( |
|
438 | 438 | sprintf( |
439 | 439 | __( 'Held for review: %s', 'invoicing' ), |
440 | 440 | $result->transactionResponse->messages->message[0]->description |
441 | 441 | ) |
442 | - ); |
|
442 | + ); |
|
443 | 443 | |
444 | - return $invoice->save(); |
|
444 | + return $invoice->save(); |
|
445 | 445 | |
446 | - } |
|
446 | + } |
|
447 | 447 | |
448 | 448 | wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) ); |
449 | 449 | |
@@ -455,13 +455,13 @@ discard block |
||
455 | 455 | } |
456 | 456 | |
457 | 457 | /** |
458 | - * Returns payment information. |
|
459 | - * |
|
460 | - * |
|
461 | - * @param array $card Card details. |
|
462 | - * @return array |
|
463 | - */ |
|
464 | - public function get_payment_information( $card ) { |
|
458 | + * Returns payment information. |
|
459 | + * |
|
460 | + * |
|
461 | + * @param array $card Card details. |
|
462 | + * @return array |
|
463 | + */ |
|
464 | + public function get_payment_information( $card ) { |
|
465 | 465 | return array( |
466 | 466 | |
467 | 467 | 'creditCard' => array ( |
@@ -474,25 +474,25 @@ discard block |
||
474 | 474 | } |
475 | 475 | |
476 | 476 | /** |
477 | - * Returns the customer profile meta name. |
|
478 | - * |
|
479 | - * |
|
480 | - * @param WPInv_Invoice $invoice Invoice. |
|
481 | - * @return string |
|
482 | - */ |
|
483 | - public function get_customer_profile_meta_name( $invoice ) { |
|
477 | + * Returns the customer profile meta name. |
|
478 | + * |
|
479 | + * |
|
480 | + * @param WPInv_Invoice $invoice Invoice. |
|
481 | + * @return string |
|
482 | + */ |
|
483 | + public function get_customer_profile_meta_name( $invoice ) { |
|
484 | 484 | return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
488 | - * Validates the submitted data. |
|
489 | - * |
|
490 | - * |
|
491 | - * @param array $submission_data Posted checkout fields. |
|
488 | + * Validates the submitted data. |
|
489 | + * |
|
490 | + * |
|
491 | + * @param array $submission_data Posted checkout fields. |
|
492 | 492 | * @param WPInv_Invoice $invoice |
493 | - * @return WP_Error|string The payment profile id |
|
494 | - */ |
|
495 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
493 | + * @return WP_Error|string The payment profile id |
|
494 | + */ |
|
495 | + public function validate_submission_data( $submission_data, $invoice ) { |
|
496 | 496 | |
497 | 497 | // Validate authentication details. |
498 | 498 | $auth = $this->get_auth_params(); |
@@ -524,13 +524,13 @@ discard block |
||
524 | 524 | } |
525 | 525 | |
526 | 526 | /** |
527 | - * Returns invoice line items. |
|
528 | - * |
|
529 | - * |
|
530 | - * @param WPInv_Invoice $invoice Invoice. |
|
531 | - * @return array |
|
532 | - */ |
|
533 | - public function get_line_items( $invoice ) { |
|
527 | + * Returns invoice line items. |
|
528 | + * |
|
529 | + * |
|
530 | + * @param WPInv_Invoice $invoice Invoice. |
|
531 | + * @return array |
|
532 | + */ |
|
533 | + public function get_line_items( $invoice ) { |
|
534 | 534 | $items = array(); |
535 | 535 | |
536 | 536 | foreach ( $invoice->get_items() as $item ) { |
@@ -568,15 +568,15 @@ discard block |
||
568 | 568 | } |
569 | 569 | |
570 | 570 | /** |
571 | - * Process Payment. |
|
572 | - * |
|
573 | - * |
|
574 | - * @param WPInv_Invoice $invoice Invoice. |
|
575 | - * @param array $submission_data Posted checkout fields. |
|
576 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
577 | - * @return array |
|
578 | - */ |
|
579 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
571 | + * Process Payment. |
|
572 | + * |
|
573 | + * |
|
574 | + * @param WPInv_Invoice $invoice Invoice. |
|
575 | + * @param array $submission_data Posted checkout fields. |
|
576 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
577 | + * @return array |
|
578 | + */ |
|
579 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
580 | 580 | |
581 | 581 | // Validate the submitted data. |
582 | 582 | $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
@@ -609,45 +609,45 @@ discard block |
||
609 | 609 | |
610 | 610 | exit; |
611 | 611 | |
612 | - } |
|
612 | + } |
|
613 | 613 | |
614 | - /** |
|
615 | - * Processes the initial payment. |
|
616 | - * |
|
614 | + /** |
|
615 | + * Processes the initial payment. |
|
616 | + * |
|
617 | 617 | * @param WPInv_Invoice $invoice Invoice. |
618 | - */ |
|
619 | - protected function process_initial_payment( $invoice ) { |
|
618 | + */ |
|
619 | + protected function process_initial_payment( $invoice ) { |
|
620 | 620 | |
621 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
621 | + $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
622 | 622 | $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
623 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
623 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
624 | 624 | |
625 | - // Do we have an error? |
|
626 | - if ( is_wp_error( $result ) ) { |
|
627 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
628 | - wpinv_send_back_to_checkout( $invoice ); |
|
629 | - } |
|
625 | + // Do we have an error? |
|
626 | + if ( is_wp_error( $result ) ) { |
|
627 | + wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
628 | + wpinv_send_back_to_checkout( $invoice ); |
|
629 | + } |
|
630 | 630 | |
631 | - // Process the response. |
|
632 | - $this->process_charge_response( $result, $invoice ); |
|
631 | + // Process the response. |
|
632 | + $this->process_charge_response( $result, $invoice ); |
|
633 | 633 | |
634 | - if ( wpinv_get_errors() ) { |
|
635 | - wpinv_send_back_to_checkout( $invoice ); |
|
636 | - } |
|
634 | + if ( wpinv_get_errors() ) { |
|
635 | + wpinv_send_back_to_checkout( $invoice ); |
|
636 | + } |
|
637 | 637 | |
638 | - } |
|
638 | + } |
|
639 | 639 | |
640 | 640 | /** |
641 | - * Processes recurring payments. |
|
642 | - * |
|
641 | + * Processes recurring payments. |
|
642 | + * |
|
643 | 643 | * @param WPInv_Invoice $invoice Invoice. |
644 | 644 | * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions. |
645 | - */ |
|
646 | - public function process_subscription( $invoice, $subscriptions ) { |
|
645 | + */ |
|
646 | + public function process_subscription( $invoice, $subscriptions ) { |
|
647 | 647 | |
648 | 648 | // Check if there is an initial amount to charge. |
649 | 649 | if ( (float) $invoice->get_total() > 0 ) { |
650 | - $this->process_initial_payment( $invoice ); |
|
650 | + $this->process_initial_payment( $invoice ); |
|
651 | 651 | } |
652 | 652 | |
653 | 653 | // Activate the subscriptions. |
@@ -665,36 +665,36 @@ discard block |
||
665 | 665 | } |
666 | 666 | } |
667 | 667 | |
668 | - // Redirect to the success page. |
|
668 | + // Redirect to the success page. |
|
669 | 669 | wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
670 | 670 | |
671 | 671 | } |
672 | 672 | |
673 | - /** |
|
674 | - * (Maybe) renews an authorize.net subscription profile. |
|
675 | - * |
|
676 | - * |
|
673 | + /** |
|
674 | + * (Maybe) renews an authorize.net subscription profile. |
|
675 | + * |
|
676 | + * |
|
677 | 677 | * @param WPInv_Subscription $subscription |
678 | - */ |
|
679 | - public function maybe_renew_subscription( $subscription ) { |
|
678 | + */ |
|
679 | + public function maybe_renew_subscription( $subscription ) { |
|
680 | 680 | |
681 | 681 | // Ensure its our subscription && it's active. |
682 | 682 | if ( $this->id == $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
683 | 683 | $this->renew_subscription( $subscription ); |
684 | 684 | } |
685 | 685 | |
686 | - } |
|
686 | + } |
|
687 | 687 | |
688 | 688 | /** |
689 | - * Renews a subscription. |
|
690 | - * |
|
689 | + * Renews a subscription. |
|
690 | + * |
|
691 | 691 | * @param WPInv_Subscription $subscription |
692 | - */ |
|
693 | - public function renew_subscription( $subscription ) { |
|
692 | + */ |
|
693 | + public function renew_subscription( $subscription ) { |
|
694 | 694 | |
695 | - // Generate the renewal invoice. |
|
696 | - $new_invoice = $subscription->create_payment(); |
|
697 | - $old_invoice = $subscription->get_parent_payment(); |
|
695 | + // Generate the renewal invoice. |
|
696 | + $new_invoice = $subscription->create_payment(); |
|
697 | + $old_invoice = $subscription->get_parent_payment(); |
|
698 | 698 | |
699 | 699 | if ( empty( $new_invoice ) ) { |
700 | 700 | $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
@@ -703,37 +703,37 @@ discard block |
||
703 | 703 | } |
704 | 704 | |
705 | 705 | // Charge the payment method. |
706 | - $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
707 | - $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
708 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
709 | - |
|
710 | - // Do we have an error? |
|
711 | - if ( is_wp_error( $result ) ) { |
|
712 | - |
|
713 | - $old_invoice->add_note( |
|
714 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
715 | - true, |
|
716 | - false, |
|
717 | - true |
|
718 | - ); |
|
719 | - $subscription->failing(); |
|
720 | - return; |
|
721 | - |
|
722 | - } |
|
723 | - |
|
724 | - // Process the response. |
|
725 | - $this->process_charge_response( $result, $new_invoice ); |
|
726 | - |
|
727 | - if ( wpinv_get_errors() ) { |
|
728 | - |
|
729 | - $old_invoice->add_note( |
|
730 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
731 | - true, |
|
732 | - false, |
|
733 | - true |
|
734 | - ); |
|
735 | - $subscription->failing(); |
|
736 | - return; |
|
706 | + $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
707 | + $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
708 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
709 | + |
|
710 | + // Do we have an error? |
|
711 | + if ( is_wp_error( $result ) ) { |
|
712 | + |
|
713 | + $old_invoice->add_note( |
|
714 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
715 | + true, |
|
716 | + false, |
|
717 | + true |
|
718 | + ); |
|
719 | + $subscription->failing(); |
|
720 | + return; |
|
721 | + |
|
722 | + } |
|
723 | + |
|
724 | + // Process the response. |
|
725 | + $this->process_charge_response( $result, $new_invoice ); |
|
726 | + |
|
727 | + if ( wpinv_get_errors() ) { |
|
728 | + |
|
729 | + $old_invoice->add_note( |
|
730 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
731 | + true, |
|
732 | + false, |
|
733 | + true |
|
734 | + ); |
|
735 | + $subscription->failing(); |
|
736 | + return; |
|
737 | 737 | |
738 | 738 | } |
739 | 739 | |
@@ -742,13 +742,13 @@ discard block |
||
742 | 742 | } |
743 | 743 | |
744 | 744 | /** |
745 | - * Processes invoice addons. |
|
746 | - * |
|
747 | - * @param WPInv_Invoice $invoice |
|
748 | - * @param GetPaid_Form_Item[] $items |
|
749 | - * @return WPInv_Invoice |
|
750 | - */ |
|
751 | - public function process_addons( $invoice, $items ) { |
|
745 | + * Processes invoice addons. |
|
746 | + * |
|
747 | + * @param WPInv_Invoice $invoice |
|
748 | + * @param GetPaid_Form_Item[] $items |
|
749 | + * @return WPInv_Invoice |
|
750 | + */ |
|
751 | + public function process_addons( $invoice, $items ) { |
|
752 | 752 | |
753 | 753 | global $getpaid_authorize_addons; |
754 | 754 | |
@@ -768,7 +768,7 @@ discard block |
||
768 | 768 | $invoice->recalculate_total(); |
769 | 769 | |
770 | 770 | $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
771 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
771 | + $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
772 | 772 | |
773 | 773 | add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 ); |
774 | 774 | $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
@@ -783,11 +783,11 @@ discard block |
||
783 | 783 | } |
784 | 784 | |
785 | 785 | /** |
786 | - * Processes invoice addons. |
|
787 | - * |
|
786 | + * Processes invoice addons. |
|
787 | + * |
|
788 | 788 | * @param array $args |
789 | - * @return array |
|
790 | - */ |
|
789 | + * @return array |
|
790 | + */ |
|
791 | 791 | public function filter_addons_request( $args ) { |
792 | 792 | |
793 | 793 | global $getpaid_authorize_addons; |
@@ -821,11 +821,11 @@ discard block |
||
821 | 821 | } |
822 | 822 | |
823 | 823 | /** |
824 | - * Filters the gateway settings. |
|
825 | - * |
|
826 | - * @param array $admin_settings |
|
827 | - */ |
|
828 | - public function admin_settings( $admin_settings ) { |
|
824 | + * Filters the gateway settings. |
|
825 | + * |
|
826 | + * @param array $admin_settings |
|
827 | + */ |
|
828 | + public function admin_settings( $admin_settings ) { |
|
829 | 829 | |
830 | 830 | $currencies = sprintf( |
831 | 831 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -865,7 +865,7 @@ discard block |
||
865 | 865 | 'readonly' => true, |
866 | 866 | ); |
867 | 867 | |
868 | - return $admin_settings; |
|
869 | - } |
|
868 | + return $admin_settings; |
|
869 | + } |
|
870 | 870 | |
871 | 871 | } |
@@ -12,474 +12,474 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Invoice_Notification_Emails { |
14 | 14 | |
15 | - /** |
|
16 | - * The array of invoice email actions. |
|
17 | - * |
|
18 | - * @param array |
|
19 | - */ |
|
20 | - public $invoice_actions; |
|
21 | - |
|
22 | - /** |
|
23 | - * Class constructor |
|
24 | - * |
|
25 | - */ |
|
26 | - public function __construct() { |
|
27 | - |
|
28 | - $this->invoice_actions = apply_filters( |
|
29 | - 'getpaid_notification_email_invoice_triggers', |
|
30 | - array( |
|
31 | - 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
32 | - 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
33 | - 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
34 | - 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
35 | - 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
36 | - 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
37 | - 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
38 | - 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
39 | - 'getpaid_new_customer_note' => 'user_note', |
|
40 | - 'getpaid_daily_maintenance' => 'overdue', |
|
41 | - ) |
|
42 | - ); |
|
43 | - |
|
44 | - $this->init_hooks(); |
|
45 | - |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Registers email hooks. |
|
50 | - */ |
|
51 | - public function init_hooks() { |
|
52 | - |
|
53 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
54 | - add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
55 | - |
|
56 | - foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | - $this->init_email_type_hook( $hook, $email_type ); |
|
58 | - } |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Registers an email hook for an invoice action. |
|
63 | - * |
|
64 | - * @param string $hook |
|
65 | - * @param string|array $email_type |
|
66 | - */ |
|
67 | - public function init_email_type_hook( $hook, $email_type ) { |
|
68 | - |
|
69 | - $email_type = wpinv_parse_list( $email_type ); |
|
70 | - |
|
71 | - foreach ( $email_type as $type ) { |
|
72 | - |
|
73 | - $email = new GetPaid_Notification_Email( $type ); |
|
74 | - |
|
75 | - // Abort if it is not active. |
|
76 | - if ( ! $email->is_active() ) { |
|
77 | - continue; |
|
78 | - } |
|
79 | - |
|
80 | - if ( method_exists( $this, $type ) ) { |
|
81 | - add_action( $hook, array( $this, $type ), 100, 2 ); |
|
82 | - continue; |
|
83 | - } |
|
84 | - |
|
85 | - do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
86 | - } |
|
87 | - |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Filters invoice merge tags. |
|
92 | - * |
|
93 | - * @param array $merge_tags |
|
94 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
95 | - */ |
|
96 | - public function invoice_merge_tags( $merge_tags, $object ) { |
|
97 | - |
|
98 | - if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
99 | - return array_merge( |
|
100 | - $merge_tags, |
|
101 | - $this->get_invoice_merge_tags( $object ) |
|
102 | - ); |
|
103 | - } |
|
104 | - |
|
105 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
106 | - return array_merge( |
|
107 | - $merge_tags, |
|
108 | - $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
109 | - ); |
|
110 | - } |
|
111 | - |
|
112 | - return $merge_tags; |
|
113 | - |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Generates invoice merge tags. |
|
118 | - * |
|
119 | - * @param WPInv_Invoice $invoice |
|
120 | - * @return array |
|
121 | - */ |
|
122 | - public function get_invoice_merge_tags( $invoice ) { |
|
123 | - |
|
124 | - // Abort if it does not exist. |
|
125 | - if ( ! $invoice->get_id() ) { |
|
126 | - return array(); |
|
127 | - } |
|
128 | - |
|
129 | - $merge_tags = array( |
|
130 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
131 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
133 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
134 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
135 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
136 | - '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
137 | - '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
138 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
139 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
140 | - '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ), |
|
141 | - '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
142 | - '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
143 | - '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
144 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
145 | - '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
146 | - '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
147 | - '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
148 | - ); |
|
149 | - |
|
150 | - $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
151 | - |
|
152 | - if ( is_array( $payment_form_data ) ) { |
|
153 | - |
|
154 | - foreach ( $payment_form_data as $label => $value ) { |
|
155 | - |
|
156 | - $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
157 | - $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
158 | - |
|
159 | - if ( is_scalar ( $value ) ) { |
|
160 | - $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
161 | - } |
|
162 | - |
|
163 | - } |
|
164 | - |
|
165 | - } |
|
166 | - |
|
167 | - return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Helper function to send an email. |
|
172 | - * |
|
173 | - * @param WPInv_Invoice $invoice |
|
174 | - * @param GetPaid_Notification_Email $email |
|
175 | - * @param string $type |
|
176 | - * @param string|array $recipients |
|
177 | - * @param array $extra_args Extra template args. |
|
178 | - */ |
|
179 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
180 | - |
|
181 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
182 | - |
|
183 | - $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
184 | - if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
185 | - return; |
|
186 | - } |
|
187 | - |
|
188 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
189 | - $merge_tags = $email->get_merge_tags(); |
|
190 | - |
|
191 | - $result = $mailer->send( |
|
192 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
193 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
194 | - $email->get_content( $merge_tags, $extra_args ), |
|
195 | - $email->get_attachments() |
|
196 | - ); |
|
197 | - |
|
198 | - // Maybe send a copy to the admin. |
|
199 | - if ( $email->include_admin_bcc() ) { |
|
200 | - $mailer->send( |
|
201 | - wpinv_get_admin_email(), |
|
202 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
203 | - $email->get_content( $merge_tags ), |
|
204 | - $email->get_attachments() |
|
205 | - ); |
|
206 | - } |
|
207 | - |
|
208 | - if ( $result ) { |
|
209 | - $invoice->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
210 | - } else { |
|
211 | - $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
212 | - } |
|
213 | - |
|
214 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
215 | - |
|
216 | - return $result; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Also send emails to any cc users. |
|
221 | - * |
|
222 | - * @param array $recipients |
|
223 | - * @param GetPaid_Notification_Email $email |
|
224 | - */ |
|
225 | - public function filter_email_recipients( $recipients, $email ) { |
|
226 | - |
|
227 | - if ( ! $email->is_admin_email() ) { |
|
228 | - $cc = $email->object->get_email_cc(); |
|
229 | - |
|
230 | - if ( ! empty( $cc ) ) { |
|
231 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
232 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
233 | - } |
|
15 | + /** |
|
16 | + * The array of invoice email actions. |
|
17 | + * |
|
18 | + * @param array |
|
19 | + */ |
|
20 | + public $invoice_actions; |
|
21 | + |
|
22 | + /** |
|
23 | + * Class constructor |
|
24 | + * |
|
25 | + */ |
|
26 | + public function __construct() { |
|
27 | + |
|
28 | + $this->invoice_actions = apply_filters( |
|
29 | + 'getpaid_notification_email_invoice_triggers', |
|
30 | + array( |
|
31 | + 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
32 | + 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
33 | + 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
34 | + 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
35 | + 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
36 | + 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
37 | + 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
38 | + 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
39 | + 'getpaid_new_customer_note' => 'user_note', |
|
40 | + 'getpaid_daily_maintenance' => 'overdue', |
|
41 | + ) |
|
42 | + ); |
|
43 | + |
|
44 | + $this->init_hooks(); |
|
45 | + |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Registers email hooks. |
|
50 | + */ |
|
51 | + public function init_hooks() { |
|
52 | + |
|
53 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
54 | + add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
55 | + |
|
56 | + foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | + $this->init_email_type_hook( $hook, $email_type ); |
|
58 | + } |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Registers an email hook for an invoice action. |
|
63 | + * |
|
64 | + * @param string $hook |
|
65 | + * @param string|array $email_type |
|
66 | + */ |
|
67 | + public function init_email_type_hook( $hook, $email_type ) { |
|
68 | + |
|
69 | + $email_type = wpinv_parse_list( $email_type ); |
|
70 | + |
|
71 | + foreach ( $email_type as $type ) { |
|
72 | + |
|
73 | + $email = new GetPaid_Notification_Email( $type ); |
|
74 | + |
|
75 | + // Abort if it is not active. |
|
76 | + if ( ! $email->is_active() ) { |
|
77 | + continue; |
|
78 | + } |
|
79 | + |
|
80 | + if ( method_exists( $this, $type ) ) { |
|
81 | + add_action( $hook, array( $this, $type ), 100, 2 ); |
|
82 | + continue; |
|
83 | + } |
|
84 | + |
|
85 | + do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
86 | + } |
|
87 | + |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Filters invoice merge tags. |
|
92 | + * |
|
93 | + * @param array $merge_tags |
|
94 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
95 | + */ |
|
96 | + public function invoice_merge_tags( $merge_tags, $object ) { |
|
97 | + |
|
98 | + if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
99 | + return array_merge( |
|
100 | + $merge_tags, |
|
101 | + $this->get_invoice_merge_tags( $object ) |
|
102 | + ); |
|
103 | + } |
|
104 | + |
|
105 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
106 | + return array_merge( |
|
107 | + $merge_tags, |
|
108 | + $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
109 | + ); |
|
110 | + } |
|
111 | + |
|
112 | + return $merge_tags; |
|
113 | + |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Generates invoice merge tags. |
|
118 | + * |
|
119 | + * @param WPInv_Invoice $invoice |
|
120 | + * @return array |
|
121 | + */ |
|
122 | + public function get_invoice_merge_tags( $invoice ) { |
|
123 | + |
|
124 | + // Abort if it does not exist. |
|
125 | + if ( ! $invoice->get_id() ) { |
|
126 | + return array(); |
|
127 | + } |
|
128 | + |
|
129 | + $merge_tags = array( |
|
130 | + '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
131 | + '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | + '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
133 | + '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
134 | + '{email}' => sanitize_email( $invoice->get_email() ), |
|
135 | + '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
136 | + '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
137 | + '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
138 | + '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
139 | + '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
140 | + '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ), |
|
141 | + '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
142 | + '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
143 | + '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
144 | + '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
145 | + '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
146 | + '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
147 | + '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
148 | + ); |
|
149 | + |
|
150 | + $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
151 | + |
|
152 | + if ( is_array( $payment_form_data ) ) { |
|
153 | + |
|
154 | + foreach ( $payment_form_data as $label => $value ) { |
|
155 | + |
|
156 | + $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
157 | + $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
158 | + |
|
159 | + if ( is_scalar ( $value ) ) { |
|
160 | + $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
161 | + } |
|
162 | + |
|
163 | + } |
|
164 | + |
|
165 | + } |
|
166 | + |
|
167 | + return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Helper function to send an email. |
|
172 | + * |
|
173 | + * @param WPInv_Invoice $invoice |
|
174 | + * @param GetPaid_Notification_Email $email |
|
175 | + * @param string $type |
|
176 | + * @param string|array $recipients |
|
177 | + * @param array $extra_args Extra template args. |
|
178 | + */ |
|
179 | + public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
180 | + |
|
181 | + do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
182 | + |
|
183 | + $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
184 | + if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
185 | + return; |
|
186 | + } |
|
187 | + |
|
188 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
189 | + $merge_tags = $email->get_merge_tags(); |
|
190 | + |
|
191 | + $result = $mailer->send( |
|
192 | + apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
193 | + $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
194 | + $email->get_content( $merge_tags, $extra_args ), |
|
195 | + $email->get_attachments() |
|
196 | + ); |
|
197 | + |
|
198 | + // Maybe send a copy to the admin. |
|
199 | + if ( $email->include_admin_bcc() ) { |
|
200 | + $mailer->send( |
|
201 | + wpinv_get_admin_email(), |
|
202 | + $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
203 | + $email->get_content( $merge_tags ), |
|
204 | + $email->get_attachments() |
|
205 | + ); |
|
206 | + } |
|
207 | + |
|
208 | + if ( $result ) { |
|
209 | + $invoice->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
210 | + } else { |
|
211 | + $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
212 | + } |
|
213 | + |
|
214 | + do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
215 | + |
|
216 | + return $result; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Also send emails to any cc users. |
|
221 | + * |
|
222 | + * @param array $recipients |
|
223 | + * @param GetPaid_Notification_Email $email |
|
224 | + */ |
|
225 | + public function filter_email_recipients( $recipients, $email ) { |
|
226 | + |
|
227 | + if ( ! $email->is_admin_email() ) { |
|
228 | + $cc = $email->object->get_email_cc(); |
|
229 | + |
|
230 | + if ( ! empty( $cc ) ) { |
|
231 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
232 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
233 | + } |
|
234 | 234 | |
235 | - } |
|
235 | + } |
|
236 | 236 | |
237 | - return $recipients; |
|
237 | + return $recipients; |
|
238 | 238 | |
239 | - } |
|
239 | + } |
|
240 | 240 | |
241 | - /** |
|
242 | - * Sends a new invoice notification. |
|
243 | - * |
|
244 | - * @param WPInv_Invoice $invoice |
|
245 | - */ |
|
246 | - public function new_invoice( $invoice ) { |
|
241 | + /** |
|
242 | + * Sends a new invoice notification. |
|
243 | + * |
|
244 | + * @param WPInv_Invoice $invoice |
|
245 | + */ |
|
246 | + public function new_invoice( $invoice ) { |
|
247 | 247 | |
248 | - // Only send this email for invoices created via the admin page. |
|
249 | - if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
250 | - return; |
|
251 | - } |
|
248 | + // Only send this email for invoices created via the admin page. |
|
249 | + if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
250 | + return; |
|
251 | + } |
|
252 | 252 | |
253 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
254 | - $recipient = wpinv_get_admin_email(); |
|
253 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
254 | + $recipient = wpinv_get_admin_email(); |
|
255 | 255 | |
256 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
256 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
257 | 257 | |
258 | - } |
|
258 | + } |
|
259 | 259 | |
260 | - /** |
|
261 | - * Sends a cancelled invoice notification. |
|
262 | - * |
|
263 | - * @param WPInv_Invoice $invoice |
|
264 | - */ |
|
265 | - public function cancelled_invoice( $invoice ) { |
|
260 | + /** |
|
261 | + * Sends a cancelled invoice notification. |
|
262 | + * |
|
263 | + * @param WPInv_Invoice $invoice |
|
264 | + */ |
|
265 | + public function cancelled_invoice( $invoice ) { |
|
266 | 266 | |
267 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
268 | - $recipient = wpinv_get_admin_email(); |
|
267 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
268 | + $recipient = wpinv_get_admin_email(); |
|
269 | 269 | |
270 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
270 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
271 | 271 | |
272 | - } |
|
272 | + } |
|
273 | 273 | |
274 | - /** |
|
275 | - * Sends a failed invoice notification. |
|
276 | - * |
|
277 | - * @param WPInv_Invoice $invoice |
|
278 | - */ |
|
279 | - public function failed_invoice( $invoice ) { |
|
274 | + /** |
|
275 | + * Sends a failed invoice notification. |
|
276 | + * |
|
277 | + * @param WPInv_Invoice $invoice |
|
278 | + */ |
|
279 | + public function failed_invoice( $invoice ) { |
|
280 | 280 | |
281 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
282 | - $recipient = wpinv_get_admin_email(); |
|
281 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
282 | + $recipient = wpinv_get_admin_email(); |
|
283 | 283 | |
284 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
284 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
285 | 285 | |
286 | - } |
|
286 | + } |
|
287 | 287 | |
288 | - /** |
|
289 | - * Sends a notification whenever an invoice is put on hold. |
|
290 | - * |
|
291 | - * @param WPInv_Invoice $invoice |
|
292 | - */ |
|
293 | - public function onhold_invoice( $invoice ) { |
|
288 | + /** |
|
289 | + * Sends a notification whenever an invoice is put on hold. |
|
290 | + * |
|
291 | + * @param WPInv_Invoice $invoice |
|
292 | + */ |
|
293 | + public function onhold_invoice( $invoice ) { |
|
294 | 294 | |
295 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
296 | - $recipient = $invoice->get_email(); |
|
295 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
296 | + $recipient = $invoice->get_email(); |
|
297 | 297 | |
298 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
298 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
299 | 299 | |
300 | - } |
|
300 | + } |
|
301 | 301 | |
302 | - /** |
|
303 | - * Sends a notification whenever an invoice is marked as processing payment. |
|
304 | - * |
|
305 | - * @param WPInv_Invoice $invoice |
|
306 | - */ |
|
307 | - public function processing_invoice( $invoice ) { |
|
302 | + /** |
|
303 | + * Sends a notification whenever an invoice is marked as processing payment. |
|
304 | + * |
|
305 | + * @param WPInv_Invoice $invoice |
|
306 | + */ |
|
307 | + public function processing_invoice( $invoice ) { |
|
308 | 308 | |
309 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
310 | - $recipient = $invoice->get_email(); |
|
309 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
310 | + $recipient = $invoice->get_email(); |
|
311 | 311 | |
312 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
312 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
313 | 313 | |
314 | - } |
|
314 | + } |
|
315 | 315 | |
316 | - /** |
|
317 | - * Sends a notification whenever an invoice is paid. |
|
318 | - * |
|
319 | - * @param WPInv_Invoice $invoice |
|
320 | - */ |
|
321 | - public function completed_invoice( $invoice ) { |
|
316 | + /** |
|
317 | + * Sends a notification whenever an invoice is paid. |
|
318 | + * |
|
319 | + * @param WPInv_Invoice $invoice |
|
320 | + */ |
|
321 | + public function completed_invoice( $invoice ) { |
|
322 | 322 | |
323 | - // (Maybe) abort if it is a renewal invoice. |
|
324 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
325 | - return; |
|
326 | - } |
|
323 | + // (Maybe) abort if it is a renewal invoice. |
|
324 | + if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
325 | + return; |
|
326 | + } |
|
327 | 327 | |
328 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
329 | - $recipient = $invoice->get_email(); |
|
328 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
329 | + $recipient = $invoice->get_email(); |
|
330 | 330 | |
331 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
331 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
332 | 332 | |
333 | - } |
|
333 | + } |
|
334 | 334 | |
335 | - /** |
|
336 | - * Sends a notification whenever an invoice is refunded. |
|
337 | - * |
|
338 | - * @param WPInv_Invoice $invoice |
|
339 | - */ |
|
340 | - public function refunded_invoice( $invoice ) { |
|
335 | + /** |
|
336 | + * Sends a notification whenever an invoice is refunded. |
|
337 | + * |
|
338 | + * @param WPInv_Invoice $invoice |
|
339 | + */ |
|
340 | + public function refunded_invoice( $invoice ) { |
|
341 | 341 | |
342 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
343 | - $recipient = $invoice->get_email(); |
|
342 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
343 | + $recipient = $invoice->get_email(); |
|
344 | 344 | |
345 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
345 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
346 | 346 | |
347 | - } |
|
347 | + } |
|
348 | 348 | |
349 | - /** |
|
350 | - * Notifies a user about new invoices |
|
351 | - * |
|
352 | - * @param WPInv_Invoice $invoice |
|
353 | - * @param bool $force |
|
354 | - */ |
|
355 | - public function user_invoice( $invoice, $force = false ) { |
|
349 | + /** |
|
350 | + * Notifies a user about new invoices |
|
351 | + * |
|
352 | + * @param WPInv_Invoice $invoice |
|
353 | + * @param bool $force |
|
354 | + */ |
|
355 | + public function user_invoice( $invoice, $force = false ) { |
|
356 | 356 | |
357 | - if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
358 | - return; |
|
359 | - } |
|
360 | - |
|
361 | - // Only send this email for invoices created via the admin page. |
|
362 | - if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
363 | - return; |
|
364 | - } |
|
357 | + if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
358 | + return; |
|
359 | + } |
|
360 | + |
|
361 | + // Only send this email for invoices created via the admin page. |
|
362 | + if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
363 | + return; |
|
364 | + } |
|
365 | 365 | |
366 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
367 | - $recipient = $invoice->get_email(); |
|
366 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
367 | + $recipient = $invoice->get_email(); |
|
368 | 368 | |
369 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
369 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
370 | 370 | |
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * Checks if an invoice is a payment form invoice. |
|
375 | - * |
|
376 | - * @param int $invoice |
|
377 | - * @return bool |
|
378 | - */ |
|
379 | - public function is_payment_form_invoice( $invoice ) { |
|
380 | - $is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) ); |
|
381 | - return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
382 | - } |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * Checks if an invoice is a payment form invoice. |
|
375 | + * |
|
376 | + * @param int $invoice |
|
377 | + * @return bool |
|
378 | + */ |
|
379 | + public function is_payment_form_invoice( $invoice ) { |
|
380 | + $is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) ); |
|
381 | + return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
382 | + } |
|
383 | 383 | |
384 | - /** |
|
385 | - * Notifies admin about new invoice notes |
|
386 | - * |
|
387 | - * @param WPInv_Invoice $invoice |
|
388 | - * @param string $note |
|
389 | - */ |
|
390 | - public function user_note( $invoice, $note ) { |
|
391 | - |
|
392 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
393 | - $recipient = $invoice->get_email(); |
|
384 | + /** |
|
385 | + * Notifies admin about new invoice notes |
|
386 | + * |
|
387 | + * @param WPInv_Invoice $invoice |
|
388 | + * @param string $note |
|
389 | + */ |
|
390 | + public function user_note( $invoice, $note ) { |
|
391 | + |
|
392 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
393 | + $recipient = $invoice->get_email(); |
|
394 | 394 | |
395 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
396 | - |
|
397 | - } |
|
398 | - |
|
399 | - /** |
|
400 | - * (Force) Sends overdue notices. |
|
401 | - * |
|
402 | - * @param WPInv_Invoice $invoice |
|
403 | - */ |
|
404 | - public function force_send_overdue_notice( $invoice ) { |
|
405 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
406 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * Sends overdue notices. |
|
411 | - * |
|
412 | - * @TODO: Create an invoices query class. |
|
413 | - */ |
|
414 | - public function overdue() { |
|
415 | - global $wpdb; |
|
416 | - |
|
417 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
418 | - |
|
419 | - // Fetch reminder days. |
|
420 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
421 | - |
|
422 | - // Abort if non is set. |
|
423 | - if ( empty( $reminder_days ) ) { |
|
424 | - return; |
|
425 | - } |
|
426 | - |
|
427 | - // Retrieve date query. |
|
428 | - $date_query = $this->get_date_query( $reminder_days ); |
|
429 | - |
|
430 | - // Invoices table. |
|
431 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
432 | - |
|
433 | - // Fetch invoices. |
|
434 | - $invoices = $wpdb->get_col( |
|
435 | - "SELECT posts.ID FROM $wpdb->posts as posts |
|
395 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
396 | + |
|
397 | + } |
|
398 | + |
|
399 | + /** |
|
400 | + * (Force) Sends overdue notices. |
|
401 | + * |
|
402 | + * @param WPInv_Invoice $invoice |
|
403 | + */ |
|
404 | + public function force_send_overdue_notice( $invoice ) { |
|
405 | + $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
406 | + return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | + * Sends overdue notices. |
|
411 | + * |
|
412 | + * @TODO: Create an invoices query class. |
|
413 | + */ |
|
414 | + public function overdue() { |
|
415 | + global $wpdb; |
|
416 | + |
|
417 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
418 | + |
|
419 | + // Fetch reminder days. |
|
420 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
421 | + |
|
422 | + // Abort if non is set. |
|
423 | + if ( empty( $reminder_days ) ) { |
|
424 | + return; |
|
425 | + } |
|
426 | + |
|
427 | + // Retrieve date query. |
|
428 | + $date_query = $this->get_date_query( $reminder_days ); |
|
429 | + |
|
430 | + // Invoices table. |
|
431 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
432 | + |
|
433 | + // Fetch invoices. |
|
434 | + $invoices = $wpdb->get_col( |
|
435 | + "SELECT posts.ID FROM $wpdb->posts as posts |
|
436 | 436 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
437 | 437 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query"); |
438 | 438 | |
439 | - foreach ( $invoices as $invoice ) { |
|
439 | + foreach ( $invoices as $invoice ) { |
|
440 | 440 | |
441 | - // Only send this email for invoices created via the admin page. |
|
442 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
443 | - $invoice = new WPInv_Invoice( $invoice ); |
|
444 | - $email->object = $invoice; |
|
441 | + // Only send this email for invoices created via the admin page. |
|
442 | + if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
443 | + $invoice = new WPInv_Invoice( $invoice ); |
|
444 | + $email->object = $invoice; |
|
445 | 445 | |
446 | - if ( $invoice->needs_payment() ) { |
|
447 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
448 | - } |
|
446 | + if ( $invoice->needs_payment() ) { |
|
447 | + $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
448 | + } |
|
449 | 449 | |
450 | - } |
|
450 | + } |
|
451 | 451 | |
452 | - } |
|
452 | + } |
|
453 | 453 | |
454 | - } |
|
454 | + } |
|
455 | 455 | |
456 | - /** |
|
457 | - * Calculates the date query for an invoices query |
|
458 | - * |
|
459 | - * @param array $reminder_days |
|
460 | - * @return string |
|
461 | - */ |
|
462 | - public function get_date_query( $reminder_days ) { |
|
456 | + /** |
|
457 | + * Calculates the date query for an invoices query |
|
458 | + * |
|
459 | + * @param array $reminder_days |
|
460 | + * @return string |
|
461 | + */ |
|
462 | + public function get_date_query( $reminder_days ) { |
|
463 | 463 | |
464 | - $date_query = array( |
|
465 | - 'relation' => 'OR' |
|
466 | - ); |
|
464 | + $date_query = array( |
|
465 | + 'relation' => 'OR' |
|
466 | + ); |
|
467 | 467 | |
468 | - foreach ( $reminder_days as $days ) { |
|
469 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
468 | + foreach ( $reminder_days as $days ) { |
|
469 | + $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
470 | 470 | |
471 | - $date_query[] = array( |
|
472 | - 'year' => $date['year'], |
|
473 | - 'month' => $date['month'], |
|
474 | - 'day' => $date['day'], |
|
475 | - ); |
|
471 | + $date_query[] = array( |
|
472 | + 'year' => $date['year'], |
|
473 | + 'month' => $date['month'], |
|
474 | + 'day' => $date['day'], |
|
475 | + ); |
|
476 | 476 | |
477 | - } |
|
477 | + } |
|
478 | 478 | |
479 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
479 | + $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
480 | 480 | |
481 | - return $date_query->get_sql(); |
|
481 | + return $date_query->get_sql(); |
|
482 | 482 | |
483 | - } |
|
483 | + } |
|
484 | 484 | |
485 | 485 | } |
@@ -16,165 +16,165 @@ |
||
16 | 16 | */ |
17 | 17 | class GetPaid_MaxMind_Geolocation { |
18 | 18 | |
19 | - /** |
|
20 | - * The service responsible for interacting with the MaxMind database. |
|
21 | - * |
|
22 | - * @var GetPaid_MaxMind_Database_Service |
|
23 | - */ |
|
24 | - private $database_service; |
|
25 | - |
|
26 | - /** |
|
27 | - * Initialize the integration. |
|
28 | - */ |
|
29 | - public function __construct() { |
|
30 | - |
|
31 | - /** |
|
32 | - * Supports overriding the database service to be used. |
|
33 | - * |
|
34 | - * @since 1.0.19 |
|
35 | - * @return mixed|null The geolocation database service. |
|
36 | - */ |
|
37 | - $this->database_service = apply_filters( 'getpaid_maxmind_geolocation_database_service', null ); |
|
38 | - if ( null === $this->database_service ) { |
|
39 | - $this->database_service = new GetPaid_MaxMind_Database_Service( $this->get_database_prefix() ); |
|
40 | - } |
|
41 | - |
|
42 | - // Bind to the scheduled updater action. |
|
43 | - add_action( 'getpaid_update_geoip_databases', array( $this, 'update_database' ) ); |
|
44 | - |
|
45 | - // Bind to the geolocation filter for MaxMind database lookups. |
|
46 | - add_filter( 'getpaid_get_geolocation', array( $this, 'get_geolocation' ), 10, 2 ); |
|
47 | - |
|
48 | - // Handle maxmind key updates. |
|
49 | - add_filter( 'wpinv_settings_sanitize_maxmind_license_key', array( $this, 'handle_key_updates' ) ); |
|
50 | - |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Get database service. |
|
55 | - * |
|
56 | - * @return GetPaid_MaxMind_Database_Service|null |
|
57 | - */ |
|
58 | - public function get_database_service() { |
|
59 | - return $this->database_service; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Checks to make sure that the license key is valid. |
|
64 | - * |
|
65 | - * @param string $license_key The new license key. |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function handle_key_updates( $license_key ) { |
|
69 | - |
|
70 | - // Trim whitespaces and strip slashes. |
|
71 | - $license_key = trim( $license_key ); |
|
72 | - |
|
73 | - // Abort if the license key is empty or unchanged. |
|
74 | - if ( empty( $license_key ) ) { |
|
75 | - return $license_key; |
|
76 | - } |
|
77 | - |
|
78 | - // Abort if a database exists and the license key is unchaged. |
|
79 | - if ( file_exists( $this->database_service->get_database_path() && $license_key == wpinv_get_option( 'maxmind_license_key' ) ) ) { |
|
80 | - return $license_key; |
|
81 | - } |
|
82 | - |
|
83 | - // Check the license key by attempting to download the Geolocation database. |
|
84 | - $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
85 | - if ( is_wp_error( $tmp_database_path ) ) { |
|
86 | - getpaid_admin()->show_error( $tmp_database_path->get_error_message() ); |
|
87 | - return $license_key; |
|
88 | - } |
|
89 | - |
|
90 | - $this->update_database( /** @scrutinizer ignore-type */ $tmp_database_path ); |
|
91 | - |
|
92 | - return $license_key; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Updates the database used for geolocation queries. |
|
97 | - * |
|
98 | - * @param string $tmp_database_path Temporary database path. |
|
99 | - */ |
|
100 | - public function update_database( $tmp_database_path = null ) { |
|
101 | - |
|
102 | - // Allow us to easily interact with the filesystem. |
|
103 | - require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
104 | - WP_Filesystem(); |
|
105 | - global $wp_filesystem; |
|
106 | - |
|
107 | - // Remove any existing archives to comply with the MaxMind TOS. |
|
108 | - $target_database_path = $this->database_service->get_database_path(); |
|
109 | - |
|
110 | - // If there's no database path, we can't store the database. |
|
111 | - if ( empty( $target_database_path ) ) { |
|
112 | - return; |
|
113 | - } |
|
114 | - |
|
115 | - if ( $wp_filesystem->exists( $target_database_path ) ) { |
|
116 | - $wp_filesystem->delete( $target_database_path ); |
|
117 | - } |
|
118 | - |
|
119 | - // We can't download a database if there's no license key configured. |
|
120 | - $license_key = wpinv_get_option( 'maxmind_license_key' ); |
|
121 | - if ( empty( $license_key ) ) { |
|
122 | - return; |
|
123 | - } |
|
124 | - |
|
125 | - if ( empty( $tmp_database_path ) ) { |
|
126 | - $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
127 | - } |
|
128 | - |
|
129 | - if ( is_wp_error( $tmp_database_path ) ) { |
|
130 | - wpinv_error_log( $tmp_database_path->get_error_message() ); |
|
131 | - return; |
|
132 | - } |
|
133 | - |
|
134 | - // Move the new database into position. |
|
135 | - $wp_filesystem->move( $tmp_database_path, $target_database_path, true ); |
|
136 | - $wp_filesystem->delete( dirname( $tmp_database_path ) ); |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Performs a geolocation lookup against the MaxMind database for the given IP address. |
|
141 | - * |
|
142 | - * @param array $data Geolocation data. |
|
143 | - * @param string $ip_address The IP address to geolocate. |
|
144 | - * @return array Geolocation including country code, state, city and postcode based on an IP address. |
|
145 | - */ |
|
146 | - public function get_geolocation( $data, $ip_address ) { |
|
147 | - |
|
148 | - if ( ! empty( $data['country'] ) || empty( $ip_address ) ) { |
|
149 | - return $data; |
|
150 | - } |
|
151 | - |
|
152 | - $country_code = $this->database_service->get_iso_country_code_for_ip( $ip_address ); |
|
153 | - |
|
154 | - return array( |
|
155 | - 'country' => $country_code, |
|
156 | - 'state' => '', |
|
157 | - 'city' => '', |
|
158 | - 'postcode' => '', |
|
159 | - ); |
|
160 | - |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Fetches the prefix for the MaxMind database file. |
|
165 | - * |
|
166 | - * @return string |
|
167 | - */ |
|
168 | - private function get_database_prefix() { |
|
169 | - |
|
170 | - $prefix = get_option( 'wpinv_maxmind_database_prefix' ); |
|
171 | - |
|
172 | - if ( empty( $prefix ) ) { |
|
173 | - $prefix = md5( uniqid( 'wpinv' ) ); |
|
174 | - update_option( 'wpinv_maxmind_database_prefix', $prefix ); |
|
175 | - } |
|
176 | - |
|
177 | - return $prefix; |
|
178 | - } |
|
19 | + /** |
|
20 | + * The service responsible for interacting with the MaxMind database. |
|
21 | + * |
|
22 | + * @var GetPaid_MaxMind_Database_Service |
|
23 | + */ |
|
24 | + private $database_service; |
|
25 | + |
|
26 | + /** |
|
27 | + * Initialize the integration. |
|
28 | + */ |
|
29 | + public function __construct() { |
|
30 | + |
|
31 | + /** |
|
32 | + * Supports overriding the database service to be used. |
|
33 | + * |
|
34 | + * @since 1.0.19 |
|
35 | + * @return mixed|null The geolocation database service. |
|
36 | + */ |
|
37 | + $this->database_service = apply_filters( 'getpaid_maxmind_geolocation_database_service', null ); |
|
38 | + if ( null === $this->database_service ) { |
|
39 | + $this->database_service = new GetPaid_MaxMind_Database_Service( $this->get_database_prefix() ); |
|
40 | + } |
|
41 | + |
|
42 | + // Bind to the scheduled updater action. |
|
43 | + add_action( 'getpaid_update_geoip_databases', array( $this, 'update_database' ) ); |
|
44 | + |
|
45 | + // Bind to the geolocation filter for MaxMind database lookups. |
|
46 | + add_filter( 'getpaid_get_geolocation', array( $this, 'get_geolocation' ), 10, 2 ); |
|
47 | + |
|
48 | + // Handle maxmind key updates. |
|
49 | + add_filter( 'wpinv_settings_sanitize_maxmind_license_key', array( $this, 'handle_key_updates' ) ); |
|
50 | + |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Get database service. |
|
55 | + * |
|
56 | + * @return GetPaid_MaxMind_Database_Service|null |
|
57 | + */ |
|
58 | + public function get_database_service() { |
|
59 | + return $this->database_service; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Checks to make sure that the license key is valid. |
|
64 | + * |
|
65 | + * @param string $license_key The new license key. |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function handle_key_updates( $license_key ) { |
|
69 | + |
|
70 | + // Trim whitespaces and strip slashes. |
|
71 | + $license_key = trim( $license_key ); |
|
72 | + |
|
73 | + // Abort if the license key is empty or unchanged. |
|
74 | + if ( empty( $license_key ) ) { |
|
75 | + return $license_key; |
|
76 | + } |
|
77 | + |
|
78 | + // Abort if a database exists and the license key is unchaged. |
|
79 | + if ( file_exists( $this->database_service->get_database_path() && $license_key == wpinv_get_option( 'maxmind_license_key' ) ) ) { |
|
80 | + return $license_key; |
|
81 | + } |
|
82 | + |
|
83 | + // Check the license key by attempting to download the Geolocation database. |
|
84 | + $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
85 | + if ( is_wp_error( $tmp_database_path ) ) { |
|
86 | + getpaid_admin()->show_error( $tmp_database_path->get_error_message() ); |
|
87 | + return $license_key; |
|
88 | + } |
|
89 | + |
|
90 | + $this->update_database( /** @scrutinizer ignore-type */ $tmp_database_path ); |
|
91 | + |
|
92 | + return $license_key; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Updates the database used for geolocation queries. |
|
97 | + * |
|
98 | + * @param string $tmp_database_path Temporary database path. |
|
99 | + */ |
|
100 | + public function update_database( $tmp_database_path = null ) { |
|
101 | + |
|
102 | + // Allow us to easily interact with the filesystem. |
|
103 | + require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
104 | + WP_Filesystem(); |
|
105 | + global $wp_filesystem; |
|
106 | + |
|
107 | + // Remove any existing archives to comply with the MaxMind TOS. |
|
108 | + $target_database_path = $this->database_service->get_database_path(); |
|
109 | + |
|
110 | + // If there's no database path, we can't store the database. |
|
111 | + if ( empty( $target_database_path ) ) { |
|
112 | + return; |
|
113 | + } |
|
114 | + |
|
115 | + if ( $wp_filesystem->exists( $target_database_path ) ) { |
|
116 | + $wp_filesystem->delete( $target_database_path ); |
|
117 | + } |
|
118 | + |
|
119 | + // We can't download a database if there's no license key configured. |
|
120 | + $license_key = wpinv_get_option( 'maxmind_license_key' ); |
|
121 | + if ( empty( $license_key ) ) { |
|
122 | + return; |
|
123 | + } |
|
124 | + |
|
125 | + if ( empty( $tmp_database_path ) ) { |
|
126 | + $tmp_database_path = $this->database_service->download_database( $license_key ); |
|
127 | + } |
|
128 | + |
|
129 | + if ( is_wp_error( $tmp_database_path ) ) { |
|
130 | + wpinv_error_log( $tmp_database_path->get_error_message() ); |
|
131 | + return; |
|
132 | + } |
|
133 | + |
|
134 | + // Move the new database into position. |
|
135 | + $wp_filesystem->move( $tmp_database_path, $target_database_path, true ); |
|
136 | + $wp_filesystem->delete( dirname( $tmp_database_path ) ); |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Performs a geolocation lookup against the MaxMind database for the given IP address. |
|
141 | + * |
|
142 | + * @param array $data Geolocation data. |
|
143 | + * @param string $ip_address The IP address to geolocate. |
|
144 | + * @return array Geolocation including country code, state, city and postcode based on an IP address. |
|
145 | + */ |
|
146 | + public function get_geolocation( $data, $ip_address ) { |
|
147 | + |
|
148 | + if ( ! empty( $data['country'] ) || empty( $ip_address ) ) { |
|
149 | + return $data; |
|
150 | + } |
|
151 | + |
|
152 | + $country_code = $this->database_service->get_iso_country_code_for_ip( $ip_address ); |
|
153 | + |
|
154 | + return array( |
|
155 | + 'country' => $country_code, |
|
156 | + 'state' => '', |
|
157 | + 'city' => '', |
|
158 | + 'postcode' => '', |
|
159 | + ); |
|
160 | + |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Fetches the prefix for the MaxMind database file. |
|
165 | + * |
|
166 | + * @return string |
|
167 | + */ |
|
168 | + private function get_database_prefix() { |
|
169 | + |
|
170 | + $prefix = get_option( 'wpinv_maxmind_database_prefix' ); |
|
171 | + |
|
172 | + if ( empty( $prefix ) ) { |
|
173 | + $prefix = md5( uniqid( 'wpinv' ) ); |
|
174 | + update_option( 'wpinv_maxmind_database_prefix', $prefix ); |
|
175 | + } |
|
176 | + |
|
177 | + return $prefix; |
|
178 | + } |
|
179 | 179 | |
180 | 180 | } |
@@ -13,30 +13,30 @@ discard block |
||
13 | 13 | class GetPaid_Manual_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 = 'manual'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
34 | - public $order = 11; |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | + public $order = 11; |
|
35 | 35 | |
36 | 36 | /** |
37 | - * Class constructor. |
|
38 | - */ |
|
39 | - public function __construct() { |
|
37 | + * Class constructor. |
|
38 | + */ |
|
39 | + public function __construct() { |
|
40 | 40 | parent::__construct(); |
41 | 41 | |
42 | 42 | $this->title = __( 'Test Gateway', 'invoicing' ); |
@@ -46,15 +46,15 @@ discard block |
||
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
49 | - * Process Payment. |
|
50 | - * |
|
51 | - * |
|
52 | - * @param WPInv_Invoice $invoice Invoice. |
|
53 | - * @param array $submission_data Posted checkout fields. |
|
54 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
55 | - * @return array |
|
56 | - */ |
|
57 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
49 | + * Process Payment. |
|
50 | + * |
|
51 | + * |
|
52 | + * @param WPInv_Invoice $invoice Invoice. |
|
53 | + * @param array $submission_data Posted checkout fields. |
|
54 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
55 | + * @return array |
|
56 | + */ |
|
57 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
58 | 58 | |
59 | 59 | // Mark it as paid. |
60 | 60 | $invoice->mark_paid(); |
@@ -85,12 +85,12 @@ discard block |
||
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
88 | - * (Maybe) renews a manual subscription profile. |
|
89 | - * |
|
90 | - * |
|
88 | + * (Maybe) renews a manual subscription profile. |
|
89 | + * |
|
90 | + * |
|
91 | 91 | * @param WPInv_Subscription $subscription |
92 | - */ |
|
93 | - public function maybe_renew_subscription( $subscription ) { |
|
92 | + */ |
|
93 | + public function maybe_renew_subscription( $subscription ) { |
|
94 | 94 | |
95 | 95 | // Ensure its our subscription && it's active. |
96 | 96 | if ( $this->id == $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
@@ -110,13 +110,13 @@ discard block |
||
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
113 | - * Processes invoice addons. |
|
114 | - * |
|
115 | - * @param WPInv_Invoice $invoice |
|
116 | - * @param GetPaid_Form_Item[] $items |
|
117 | - * @return WPInv_Invoice |
|
118 | - */ |
|
119 | - public function process_addons( $invoice, $items ) { |
|
113 | + * Processes invoice addons. |
|
114 | + * |
|
115 | + * @param WPInv_Invoice $invoice |
|
116 | + * @param GetPaid_Form_Item[] $items |
|
117 | + * @return WPInv_Invoice |
|
118 | + */ |
|
119 | + public function process_addons( $invoice, $items ) { |
|
120 | 120 | |
121 | 121 | foreach ( $items as $item ) { |
122 | 122 | $invoice->add_item( $item ); |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * |
7 | 7 | */ |
8 | 8 | if ( ! defined( 'ABSPATH' ) ) { |
9 | - exit; |
|
9 | + exit; |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | /** |
@@ -15,71 +15,71 @@ discard block |
||
15 | 15 | class WPInv_Admin_Addons extends Ayecode_Addons { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * Get the extensions page tabs. |
|
20 | - * |
|
21 | - * @return array of tabs. |
|
22 | - */ |
|
23 | - public function get_tabs(){ |
|
24 | - $tabs = array( |
|
25 | - 'addons' => __("Addons", "invoicing"), |
|
18 | + /** |
|
19 | + * Get the extensions page tabs. |
|
20 | + * |
|
21 | + * @return array of tabs. |
|
22 | + */ |
|
23 | + public function get_tabs(){ |
|
24 | + $tabs = array( |
|
25 | + 'addons' => __("Addons", "invoicing"), |
|
26 | 26 | 'gateways' => __("Payment Gateways", "invoicing"), |
27 | 27 | 'recommended_plugins' => __("Recommended plugins", "invoicing"), |
28 | 28 | 'membership' => __("Membership", "invoicing"), |
29 | - ); |
|
30 | - |
|
31 | - return $tabs; |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * Get section content for the addons screen. |
|
36 | - * |
|
37 | - * @param string $section_id |
|
38 | - * |
|
39 | - * @return array |
|
40 | - */ |
|
41 | - public function get_section_data( $section_id ) { |
|
42 | - $section = self::get_tab( $section_id ); |
|
43 | - $api_url = "https://wpinvoicing.com/edd-api/v2/products/"; |
|
44 | - $section_data = new stdClass(); |
|
45 | - |
|
46 | - if($section_id=='recommended_plugins'){ |
|
47 | - $section_data->products = self::get_recommend_wp_plugins_edd_formatted(); |
|
48 | - } |
|
49 | - elseif ( ! empty( $section ) ) { |
|
50 | - if ( false === ( $section_data = get_transient( 'wpi_addons_section_' . $section_id ) ) ) { //@todo restore after testing |
|
51 | - //if ( 1==1) { |
|
52 | - |
|
53 | - $query_args = array( 'category' => $section_id, 'number' => 100); |
|
54 | - $query_args = apply_filters('wpeu_edd_api_query_args',$query_args,$api_url,$section_id); |
|
55 | - |
|
56 | - $raw_section = wp_safe_remote_get( esc_url_raw( add_query_arg($query_args ,$api_url) ), array( 'user-agent' => 'Invoicing Addons Page','timeout' => 15, ) ); |
|
57 | - |
|
58 | - if ( ! is_wp_error( $raw_section ) ) { |
|
59 | - $section_data = json_decode( wp_remote_retrieve_body( $raw_section ) ); |
|
60 | - |
|
61 | - if ( ! empty( $section_data->products ) ) { |
|
62 | - set_transient( 'wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS ); |
|
63 | - } |
|
64 | - } |
|
65 | - } |
|
66 | - } |
|
67 | - |
|
68 | - $products = isset($section_data->products) ? $section_data->products : ''; |
|
69 | - |
|
70 | - return apply_filters( 'wpi_addons_section_data', $products, $section_id ); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Outputs a button. |
|
75 | - *ccc |
|
76 | - * @param string $url |
|
77 | - * @param string $text |
|
78 | - * @param string $theme |
|
79 | - * @param string $plugin |
|
80 | - */ |
|
81 | - public function output_button( $addon ) { |
|
82 | - $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
29 | + ); |
|
30 | + |
|
31 | + return $tabs; |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * Get section content for the addons screen. |
|
36 | + * |
|
37 | + * @param string $section_id |
|
38 | + * |
|
39 | + * @return array |
|
40 | + */ |
|
41 | + public function get_section_data( $section_id ) { |
|
42 | + $section = self::get_tab( $section_id ); |
|
43 | + $api_url = "https://wpinvoicing.com/edd-api/v2/products/"; |
|
44 | + $section_data = new stdClass(); |
|
45 | + |
|
46 | + if($section_id=='recommended_plugins'){ |
|
47 | + $section_data->products = self::get_recommend_wp_plugins_edd_formatted(); |
|
48 | + } |
|
49 | + elseif ( ! empty( $section ) ) { |
|
50 | + if ( false === ( $section_data = get_transient( 'wpi_addons_section_' . $section_id ) ) ) { //@todo restore after testing |
|
51 | + //if ( 1==1) { |
|
52 | + |
|
53 | + $query_args = array( 'category' => $section_id, 'number' => 100); |
|
54 | + $query_args = apply_filters('wpeu_edd_api_query_args',$query_args,$api_url,$section_id); |
|
55 | + |
|
56 | + $raw_section = wp_safe_remote_get( esc_url_raw( add_query_arg($query_args ,$api_url) ), array( 'user-agent' => 'Invoicing Addons Page','timeout' => 15, ) ); |
|
57 | + |
|
58 | + if ( ! is_wp_error( $raw_section ) ) { |
|
59 | + $section_data = json_decode( wp_remote_retrieve_body( $raw_section ) ); |
|
60 | + |
|
61 | + if ( ! empty( $section_data->products ) ) { |
|
62 | + set_transient( 'wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS ); |
|
63 | + } |
|
64 | + } |
|
65 | + } |
|
66 | + } |
|
67 | + |
|
68 | + $products = isset($section_data->products) ? $section_data->products : ''; |
|
69 | + |
|
70 | + return apply_filters( 'wpi_addons_section_data', $products, $section_id ); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Outputs a button. |
|
75 | + *ccc |
|
76 | + * @param string $url |
|
77 | + * @param string $text |
|
78 | + * @param string $theme |
|
79 | + * @param string $plugin |
|
80 | + */ |
|
81 | + public function output_button( $addon ) { |
|
82 | + $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
83 | 83 | // $button_text = __('Free','invoicing'); |
84 | 84 | // $licensing = false; |
85 | 85 | // $installed = false; |
@@ -91,123 +91,123 @@ discard block |
||
91 | 91 | // $install_status = 'get'; |
92 | 92 | // $onclick = ''; |
93 | 93 | |
94 | - $wp_org_themes = array('supreme-directory','directory-starter'); |
|
95 | - |
|
96 | - $button_args = array( |
|
97 | - 'type' => ($current_tab == 'addons' || $current_tab =='gateways') ? 'addons' : $current_tab, |
|
98 | - 'id' => isset($addon->info->id) ? absint($addon->info->id) : '', |
|
99 | - 'title' => isset($addon->info->title) ? $addon->info->title : '', |
|
100 | - 'button_text' => __('Free','invoicing'), |
|
101 | - 'price_text' => __('Free','invoicing'), |
|
102 | - 'link' => isset($addon->info->link) ? $addon->info->link : '', // link to product |
|
103 | - 'url' => isset($addon->info->link) ? $addon->info->link : '', // button url |
|
104 | - 'class' => 'button-primary', |
|
105 | - 'install_status' => 'get', |
|
106 | - 'installed' => false, |
|
107 | - 'price' => '', |
|
108 | - 'licensing' => isset($addon->licensing->enabled) && $addon->licensing->enabled ? true : false, |
|
109 | - 'license' => isset($addon->licensing->license) && $addon->licensing->license ? $addon->licensing->license : '', |
|
110 | - 'onclick' => '', |
|
111 | - 'slug' => isset($addon->info->slug) ? $addon->info->slug : '', |
|
112 | - 'active' => false, |
|
113 | - 'file' => '', |
|
114 | - 'update_url' => '', |
|
115 | - ); |
|
116 | - |
|
117 | - if( 'getpaid-stripe-payments' == $addon->info->slug || ( $current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug )){ |
|
118 | - include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
|
119 | - $status = install_plugin_install_status(array("slug"=>$button_args['slug'],"version"=>"")); |
|
120 | - $button_args['install_status'] = isset($status['status']) ? $status['status'] : 'install'; |
|
121 | - $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
|
122 | - }elseif( ($current_tab == 'addons' || $current_tab =='gateways') && isset($addon->info->id) && $addon->info->id){ |
|
123 | - include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
|
124 | - if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
|
125 | - $status = self::install_plugin_install_status($addon); |
|
126 | - $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
|
127 | - if(isset($status['status'])){$button_args['install_status'] = $status['status'];} |
|
128 | - $button_args['update_url'] = "https://wpinvoicing.com"; |
|
129 | - }elseif($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) { |
|
130 | - if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
|
131 | - $button_args['installed'] = self::is_theme_installed($addon); |
|
132 | - if(!in_array($button_args['slug'],$wp_org_themes)){ |
|
133 | - $button_args['update_url'] = "https://wpinvoicing.com"; |
|
134 | - } |
|
135 | - } |
|
136 | - |
|
137 | - // set price |
|
138 | - if(isset($addon->pricing) && !empty($addon->pricing)){ |
|
139 | - if(is_object($addon->pricing)){ |
|
140 | - $prices = (Array)$addon->pricing; |
|
141 | - $button_args['price'] = reset($prices); |
|
142 | - }elseif(isset($addon->pricing)){ |
|
143 | - $button_args['price'] = $addon->pricing; |
|
144 | - } |
|
145 | - } |
|
146 | - |
|
147 | - // set price text |
|
148 | - if( $button_args['price'] && $button_args['price'] != '0.00' ){ |
|
149 | - $button_args['price_text'] = sprintf( __('From: $%d', 'invoicing'), $button_args['price']); |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - // set if installed |
|
154 | - if(in_array($button_args['install_status'], array('installed','latest_installed','update_available','newer_installed'))){ |
|
155 | - $button_args['installed'] = true; |
|
156 | - } |
|
94 | + $wp_org_themes = array('supreme-directory','directory-starter'); |
|
95 | + |
|
96 | + $button_args = array( |
|
97 | + 'type' => ($current_tab == 'addons' || $current_tab =='gateways') ? 'addons' : $current_tab, |
|
98 | + 'id' => isset($addon->info->id) ? absint($addon->info->id) : '', |
|
99 | + 'title' => isset($addon->info->title) ? $addon->info->title : '', |
|
100 | + 'button_text' => __('Free','invoicing'), |
|
101 | + 'price_text' => __('Free','invoicing'), |
|
102 | + 'link' => isset($addon->info->link) ? $addon->info->link : '', // link to product |
|
103 | + 'url' => isset($addon->info->link) ? $addon->info->link : '', // button url |
|
104 | + 'class' => 'button-primary', |
|
105 | + 'install_status' => 'get', |
|
106 | + 'installed' => false, |
|
107 | + 'price' => '', |
|
108 | + 'licensing' => isset($addon->licensing->enabled) && $addon->licensing->enabled ? true : false, |
|
109 | + 'license' => isset($addon->licensing->license) && $addon->licensing->license ? $addon->licensing->license : '', |
|
110 | + 'onclick' => '', |
|
111 | + 'slug' => isset($addon->info->slug) ? $addon->info->slug : '', |
|
112 | + 'active' => false, |
|
113 | + 'file' => '', |
|
114 | + 'update_url' => '', |
|
115 | + ); |
|
116 | + |
|
117 | + if( 'getpaid-stripe-payments' == $addon->info->slug || ( $current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug )){ |
|
118 | + include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
|
119 | + $status = install_plugin_install_status(array("slug"=>$button_args['slug'],"version"=>"")); |
|
120 | + $button_args['install_status'] = isset($status['status']) ? $status['status'] : 'install'; |
|
121 | + $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
|
122 | + }elseif( ($current_tab == 'addons' || $current_tab =='gateways') && isset($addon->info->id) && $addon->info->id){ |
|
123 | + include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
|
124 | + if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
|
125 | + $status = self::install_plugin_install_status($addon); |
|
126 | + $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
|
127 | + if(isset($status['status'])){$button_args['install_status'] = $status['status'];} |
|
128 | + $button_args['update_url'] = "https://wpinvoicing.com"; |
|
129 | + }elseif($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) { |
|
130 | + if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
|
131 | + $button_args['installed'] = self::is_theme_installed($addon); |
|
132 | + if(!in_array($button_args['slug'],$wp_org_themes)){ |
|
133 | + $button_args['update_url'] = "https://wpinvoicing.com"; |
|
134 | + } |
|
135 | + } |
|
136 | + |
|
137 | + // set price |
|
138 | + if(isset($addon->pricing) && !empty($addon->pricing)){ |
|
139 | + if(is_object($addon->pricing)){ |
|
140 | + $prices = (Array)$addon->pricing; |
|
141 | + $button_args['price'] = reset($prices); |
|
142 | + }elseif(isset($addon->pricing)){ |
|
143 | + $button_args['price'] = $addon->pricing; |
|
144 | + } |
|
145 | + } |
|
146 | + |
|
147 | + // set price text |
|
148 | + if( $button_args['price'] && $button_args['price'] != '0.00' ){ |
|
149 | + $button_args['price_text'] = sprintf( __('From: $%d', 'invoicing'), $button_args['price']); |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + // set if installed |
|
154 | + if(in_array($button_args['install_status'], array('installed','latest_installed','update_available','newer_installed'))){ |
|
155 | + $button_args['installed'] = true; |
|
156 | + } |
|
157 | 157 | |
158 | 158 | // print_r($button_args); |
159 | - // set if active |
|
160 | - if($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')){ |
|
161 | - if($button_args['type'] != 'themes'){ |
|
162 | - $button_args['active'] = is_plugin_active($button_args['file']); |
|
163 | - }else{ |
|
164 | - $button_args['active'] = self::is_theme_active($addon); |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - // set button text and class |
|
169 | - if($button_args['active']){ |
|
170 | - $button_args['button_text'] = __('Active','invoicing'); |
|
171 | - $button_args['class'] = ' button-secondary disabled '; |
|
172 | - }elseif($button_args['installed']){ |
|
173 | - $button_args['button_text'] = __('Activate','invoicing'); |
|
174 | - |
|
175 | - if($button_args['type'] != 'themes'){ |
|
176 | - if ( current_user_can( 'manage_options' ) ) { |
|
177 | - $button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin='.$button_args['file']), 'activate-plugin_' . $button_args['file']); |
|
178 | - }else{ |
|
179 | - $button_args['url'] = '#'; |
|
180 | - } |
|
181 | - }else{ |
|
182 | - if ( current_user_can( 'switch_themes' ) ) { |
|
183 | - $button_args['url'] = self::get_theme_activation_url($addon); |
|
184 | - }else{ |
|
185 | - $button_args['url'] = '#'; |
|
186 | - } |
|
187 | - } |
|
188 | - |
|
189 | - }else{ |
|
190 | - if($button_args['type'] == 'recommended_plugins'){ |
|
191 | - $button_args['button_text'] = __('Install','invoicing'); |
|
192 | - }else{ |
|
193 | - $button_args['button_text'] = __('Get it','invoicing'); |
|
194 | - |
|
195 | - /*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){ |
|
159 | + // set if active |
|
160 | + if($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')){ |
|
161 | + if($button_args['type'] != 'themes'){ |
|
162 | + $button_args['active'] = is_plugin_active($button_args['file']); |
|
163 | + }else{ |
|
164 | + $button_args['active'] = self::is_theme_active($addon); |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + // set button text and class |
|
169 | + if($button_args['active']){ |
|
170 | + $button_args['button_text'] = __('Active','invoicing'); |
|
171 | + $button_args['class'] = ' button-secondary disabled '; |
|
172 | + }elseif($button_args['installed']){ |
|
173 | + $button_args['button_text'] = __('Activate','invoicing'); |
|
174 | + |
|
175 | + if($button_args['type'] != 'themes'){ |
|
176 | + if ( current_user_can( 'manage_options' ) ) { |
|
177 | + $button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin='.$button_args['file']), 'activate-plugin_' . $button_args['file']); |
|
178 | + }else{ |
|
179 | + $button_args['url'] = '#'; |
|
180 | + } |
|
181 | + }else{ |
|
182 | + if ( current_user_can( 'switch_themes' ) ) { |
|
183 | + $button_args['url'] = self::get_theme_activation_url($addon); |
|
184 | + }else{ |
|
185 | + $button_args['url'] = '#'; |
|
186 | + } |
|
187 | + } |
|
188 | + |
|
189 | + }else{ |
|
190 | + if($button_args['type'] == 'recommended_plugins'){ |
|
191 | + $button_args['button_text'] = __('Install','invoicing'); |
|
192 | + }else{ |
|
193 | + $button_args['button_text'] = __('Get it','invoicing'); |
|
194 | + |
|
195 | + /*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){ |
|
196 | 196 | $button_args['button_text'] = __('Install','invoicing'); |
197 | 197 | $button_args['url'] = self::get_theme_install_url($button_args['slug']); |
198 | 198 | $button_args['onclick'] = 'gd_set_button_installing(this);'; |
199 | 199 | }*/ |
200 | 200 | |
201 | - } |
|
202 | - } |
|
201 | + } |
|
202 | + } |
|
203 | 203 | |
204 | 204 | |
205 | - // filter the button arguments |
|
206 | - $button_args = apply_filters('edd_api_button_args',$button_args); |
|
205 | + // filter the button arguments |
|
206 | + $button_args = apply_filters('edd_api_button_args',$button_args); |
|
207 | 207 | // print_r($button_args); |
208 | - // set price text |
|
209 | - if(isset($button_args['price_text'])){ |
|
210 | - ?> |
|
208 | + // set price text |
|
209 | + if(isset($button_args['price_text'])){ |
|
210 | + ?> |
|
211 | 211 | <a |
212 | 212 | target="_blank" |
213 | 213 | class="addons-price-text" |
@@ -215,15 +215,15 @@ discard block |
||
215 | 215 | <?php echo esc_html( $button_args['price_text'] ); ?> |
216 | 216 | </a> |
217 | 217 | <?php |
218 | - } |
|
218 | + } |
|
219 | 219 | |
220 | 220 | |
221 | - $target = ''; |
|
222 | - if ( ! empty( $button_args['url'] ) ) { |
|
223 | - $target = strpos($button_args['url'], get_site_url()) !== false ? '' : ' target="_blank" '; |
|
224 | - } |
|
221 | + $target = ''; |
|
222 | + if ( ! empty( $button_args['url'] ) ) { |
|
223 | + $target = strpos($button_args['url'], get_site_url()) !== false ? '' : ' target="_blank" '; |
|
224 | + } |
|
225 | 225 | |
226 | - ?> |
|
226 | + ?> |
|
227 | 227 | <a |
228 | 228 | data-licence="<?php echo esc_attr($button_args['license']);?>" |
229 | 229 | data-licensing="<?php echo $button_args['licensing'] ? 1 : 0;?>" |
@@ -246,33 +246,33 @@ discard block |
||
246 | 246 | <?php |
247 | 247 | |
248 | 248 | |
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * Handles output of the addons page in admin. |
|
254 | - */ |
|
255 | - public function output() { |
|
256 | - $tabs = self::get_tabs(); |
|
257 | - $sections = self::get_sections(); |
|
258 | - $theme = wp_get_theme(); |
|
259 | - $section_keys = array_keys( $sections ); |
|
260 | - $current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys ); |
|
261 | - $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
262 | - include_once( WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php' ); |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * A list of recommended wp.org plugins. |
|
267 | - * @return array |
|
268 | - */ |
|
269 | - public function get_recommend_wp_plugins(){ |
|
270 | - $plugins = array( |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * Handles output of the addons page in admin. |
|
254 | + */ |
|
255 | + public function output() { |
|
256 | + $tabs = self::get_tabs(); |
|
257 | + $sections = self::get_sections(); |
|
258 | + $theme = wp_get_theme(); |
|
259 | + $section_keys = array_keys( $sections ); |
|
260 | + $current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys ); |
|
261 | + $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
262 | + include_once( WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php' ); |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * A list of recommended wp.org plugins. |
|
267 | + * @return array |
|
268 | + */ |
|
269 | + public function get_recommend_wp_plugins(){ |
|
270 | + $plugins = array( |
|
271 | 271 | 'invoicing-quotes' => array( |
272 | 272 | 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
273 | 273 | 'slug' => 'invoicing-quotes', |
274 | - 'name' => 'Quotes', |
|
275 | - 'thumbnail' => 'https://ps.w.org/invoicing-quotes/assets/banner-772x250.jpg', |
|
274 | + 'name' => 'Quotes', |
|
275 | + 'thumbnail' => 'https://ps.w.org/invoicing-quotes/assets/banner-772x250.jpg', |
|
276 | 276 | 'desc' => __('Allows you to create quotes, send them to clients and convert them to Invoices when accepted by the customer.','invoicing'), |
277 | 277 | ), |
278 | 278 | 'geodirectory' => array( |
@@ -287,8 +287,8 @@ discard block |
||
287 | 287 | 'name' => 'UsersWP', |
288 | 288 | 'desc' => __('Allow frontend user login and registration as well as have slick profile pages.','invoicing'), |
289 | 289 | ), |
290 | - ); |
|
290 | + ); |
|
291 | 291 | |
292 | - return $plugins; |
|
293 | - } |
|
292 | + return $plugins; |
|
293 | + } |
|
294 | 294 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
7 | - exit; |
|
7 | + exit; |
|
8 | 8 | } |
9 | 9 | add_ThickBox(); |
10 | 10 | ?> |
@@ -14,18 +14,18 @@ discard block |
||
14 | 14 | <?php if ( $tabs ){ ?> |
15 | 15 | <nav class="nav-tab-wrapper wpi-nav-tab-wrapper"> |
16 | 16 | <?php |
17 | - foreach ( $tabs as $name => $label ) { |
|
18 | - echo '<a href="' . admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . $label . '</a>'; |
|
19 | - } |
|
20 | - do_action( 'wpi_addons_tabs' ); |
|
21 | - ?> |
|
17 | + foreach ( $tabs as $name => $label ) { |
|
18 | + echo '<a href="' . admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . $label . '</a>'; |
|
19 | + } |
|
20 | + do_action( 'wpi_addons_tabs' ); |
|
21 | + ?> |
|
22 | 22 | </nav> |
23 | 23 | |
24 | 24 | <?php |
25 | 25 | |
26 | - if($current_tab == 'membership'){ |
|
26 | + if($current_tab == 'membership'){ |
|
27 | 27 | |
28 | - ?> |
|
28 | + ?> |
|
29 | 29 | |
30 | 30 | <div class="wpi-membership-tab-conatiner"> |
31 | 31 | <div class="membership-content"> |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | <h2><?php _e("Have a membership key?","invoicing");?></h2> |
37 | 37 | <p> |
38 | 38 | <?php |
39 | - $wpeu_admin = new External_Updates_Admin('wpinvoicing.com','1'); |
|
40 | - echo $wpeu_admin->render_licence_actions('wpinvoicing.com', 'membership',array(95, 106, 108,12351)); |
|
41 | - ?> |
|
39 | + $wpeu_admin = new External_Updates_Admin('wpinvoicing.com','1'); |
|
40 | + echo $wpeu_admin->render_licence_actions('wpinvoicing.com', 'membership',array(95, 106, 108,12351)); |
|
41 | + ?> |
|
42 | 42 | </p> |
43 | 43 | <?php }?> |
44 | 44 | |
@@ -48,13 +48,13 @@ discard block |
||
48 | 48 | <div class="feature-list"> |
49 | 49 | <ul> |
50 | 50 | <?php |
51 | - $addon_obj = new WPInv_Admin_Addons(); |
|
52 | - if ($addons = $addon_obj->get_section_data( 'addons' ) ) { |
|
53 | - foreach ( $addons as $addon ) { |
|
54 | - echo '<li><i class="far fa-check-circle fa-sm"></i> '.esc_html( $addon->info->title ).'</li>'; |
|
55 | - } |
|
56 | - } |
|
57 | - ?> |
|
51 | + $addon_obj = new WPInv_Admin_Addons(); |
|
52 | + if ($addons = $addon_obj->get_section_data( 'addons' ) ) { |
|
53 | + foreach ( $addons as $addon ) { |
|
54 | + echo '<li><i class="far fa-check-circle fa-sm"></i> '.esc_html( $addon->info->title ).'</li>'; |
|
55 | + } |
|
56 | + } |
|
57 | + ?> |
|
58 | 58 | </ul> |
59 | 59 | |
60 | 60 | <div class="feature-cta"> |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | <h3><?php _e("Included Gateways:","invoicing");?></h3> |
66 | 66 | <ul> |
67 | 67 | <?php |
68 | - if ($addons = $addon_obj->get_section_data( 'gateways' ) ) { |
|
69 | - foreach ( $addons as $addon ) { |
|
70 | - echo '<li><i class="far fa-check-circle fa-sm"></i> '.esc_html( $addon->info->title ).'</li>'; |
|
71 | - } |
|
72 | - } |
|
73 | - ?> |
|
68 | + if ($addons = $addon_obj->get_section_data( 'gateways' ) ) { |
|
69 | + foreach ( $addons as $addon ) { |
|
70 | + echo '<li><i class="far fa-check-circle fa-sm"></i> '.esc_html( $addon->info->title ).'</li>'; |
|
71 | + } |
|
72 | + } |
|
73 | + ?> |
|
74 | 74 | </ul> |
75 | 75 | </div> |
76 | 76 | |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | <div class="testimonial-content"> |
82 | 82 | <div class="t-image"> |
83 | 83 | <?php |
84 | - echo '<img src="' . plugins_url( 'images/t-image2.png', dirname(__FILE__) ) . '" > '; |
|
85 | - ?> |
|
84 | + echo '<img src="' . plugins_url( 'images/t-image2.png', dirname(__FILE__) ) . '" > '; |
|
85 | + ?> |
|
86 | 86 | </div> |
87 | 87 | <div class="t-content"> |
88 | 88 | <p> |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | <div class="testimonial-content"> |
102 | 102 | <div class="t-image"> |
103 | 103 | <?php |
104 | - echo '<img src="' . plugins_url( 'images/t-image1.png', dirname(__FILE__) ) . '" > '; |
|
105 | - ?> |
|
104 | + echo '<img src="' . plugins_url( 'images/t-image1.png', dirname(__FILE__) ) . '" > '; |
|
105 | + ?> |
|
106 | 106 | </div> |
107 | 107 | <div class="t-content"> |
108 | 108 | <p> |
@@ -126,20 +126,20 @@ discard block |
||
126 | 126 | </div> |
127 | 127 | </div> |
128 | 128 | <?php |
129 | - }else{ |
|
130 | - $installed_plugins = get_plugins(); |
|
129 | + }else{ |
|
130 | + $installed_plugins = get_plugins(); |
|
131 | 131 | $addon_obj = new WPInv_Admin_Addons(); |
132 | - if ($addons = $addon_obj->get_section_data( $current_tab ) ) : |
|
133 | - ?> |
|
132 | + if ($addons = $addon_obj->get_section_data( $current_tab ) ) : |
|
133 | + ?> |
|
134 | 134 | <ul class="wpi-products"><?php foreach ( $addons as $addon ) : |
135 | 135 | if(965==$addon->info->id){continue;}// don't show quote add on |
136 | - ?><li class="wpi-product"> |
|
136 | + ?><li class="wpi-product"> |
|
137 | 137 | <div class="wpi-product-title"> |
138 | 138 | <h3><?php |
139 | - if ( ! empty( $addon->info->excerpt) ){ |
|
140 | - echo wpi_help_tip( $addon->info->excerpt ); |
|
141 | - } |
|
142 | - echo esc_html( $addon->info->title ); ?></h3> |
|
139 | + if ( ! empty( $addon->info->excerpt) ){ |
|
140 | + echo wpi_help_tip( $addon->info->excerpt ); |
|
141 | + } |
|
142 | + echo esc_html( $addon->info->title ); ?></h3> |
|
143 | 143 | </div> |
144 | 144 | |
145 | 145 | <span class="wpi-product-image"> |
@@ -147,32 +147,32 @@ discard block |
||
147 | 147 | <img src="<?php echo esc_attr( $addon->info->thumbnail ); ?>"/> |
148 | 148 | <?php endif; |
149 | 149 | |
150 | - if ( 'stripe-payment-gateway' == $addon->info->slug ) { |
|
151 | - $addon->info->slug = 'getpaid-stripe-payments'; |
|
152 | - $addon->info->link = 'https://wordpress.org/plugins/getpaid-stripe-payments/'; |
|
153 | - } |
|
154 | - |
|
155 | - if(isset($addon->info->link) && substr( $addon->info->link, 0, 21 ) === "https://wordpress.org"){ |
|
156 | - echo '<a href="'.admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug).'&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
|
157 | - echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
158 | - echo '</a>'; |
|
159 | - }elseif(isset($addon->info->link) && substr( $addon->info->link, 0, 23 ) === "https://wpinvoicing.com"){ |
|
160 | - if(defined('WP_EASY_UPDATES_ACTIVE')){ |
|
161 | - $url = admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug.'&width=770&height=660&item_id='.$addon->info->id.'&update_url=https://wpinvoicing.com&TB_iframe=true'); |
|
162 | - }else{ |
|
163 | - // if installed show activation link |
|
164 | - if(isset($installed_plugins['wp-easy-updates/external-updates.php'])){ |
|
165 | - $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation'; |
|
166 | - }else{ |
|
167 | - $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external'; |
|
168 | - } |
|
169 | - } |
|
170 | - echo '<a href="'.$url.'" class="thickbox">'; |
|
171 | - echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
172 | - echo '</a>'; |
|
173 | - } |
|
174 | - |
|
175 | - ?> |
|
150 | + if ( 'stripe-payment-gateway' == $addon->info->slug ) { |
|
151 | + $addon->info->slug = 'getpaid-stripe-payments'; |
|
152 | + $addon->info->link = 'https://wordpress.org/plugins/getpaid-stripe-payments/'; |
|
153 | + } |
|
154 | + |
|
155 | + if(isset($addon->info->link) && substr( $addon->info->link, 0, 21 ) === "https://wordpress.org"){ |
|
156 | + echo '<a href="'.admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug).'&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
|
157 | + echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
158 | + echo '</a>'; |
|
159 | + }elseif(isset($addon->info->link) && substr( $addon->info->link, 0, 23 ) === "https://wpinvoicing.com"){ |
|
160 | + if(defined('WP_EASY_UPDATES_ACTIVE')){ |
|
161 | + $url = admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug.'&width=770&height=660&item_id='.$addon->info->id.'&update_url=https://wpinvoicing.com&TB_iframe=true'); |
|
162 | + }else{ |
|
163 | + // if installed show activation link |
|
164 | + if(isset($installed_plugins['wp-easy-updates/external-updates.php'])){ |
|
165 | + $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation'; |
|
166 | + }else{ |
|
167 | + $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external'; |
|
168 | + } |
|
169 | + } |
|
170 | + echo '<a href="'.$url.'" class="thickbox">'; |
|
171 | + echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
172 | + echo '</a>'; |
|
173 | + } |
|
174 | + |
|
175 | + ?> |
|
176 | 176 | |
177 | 177 | </span> |
178 | 178 | |
@@ -180,15 +180,15 @@ discard block |
||
180 | 180 | <span class="wpi-product-button"> |
181 | 181 | <?php |
182 | 182 | $addon_obj->output_button( $addon ); |
183 | - ?> |
|
183 | + ?> |
|
184 | 184 | </span> |
185 | 185 | |
186 | 186 | <span class="wpi-price"><?php //print_r($addon); //echo wp_kses_post( $addon->price ); ?></span></li><?php endforeach; ?></ul> |
187 | 187 | <?php endif; |
188 | - } |
|
188 | + } |
|
189 | 189 | |
190 | - } |
|
191 | - ?> |
|
190 | + } |
|
191 | + ?> |
|
192 | 192 | |
193 | 193 | |
194 | 194 | <div class="clearfix" ></div> |
@@ -207,8 +207,8 @@ discard block |
||
207 | 207 | <input class="wpeu-licence-key" type="text" placeholder="<?php _e("Enter your licence key",'invoicing');?>"> <button class="button-primary wpeu-licence-popup-button" ><?php _e("Install",'invoicing');?></button> |
208 | 208 | <br> |
209 | 209 | <?php |
210 | - echo sprintf( __('%sFind your licence key here%s OR %sBuy one here%s', 'invoicing'), '<a href="https://wpinvoicing.com/your-account/" target="_blank">','</a>','<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">','</a>' ); |
|
211 | - ?> |
|
210 | + echo sprintf( __('%sFind your licence key here%s OR %sBuy one here%s', 'invoicing'), '<a href="https://wpinvoicing.com/your-account/" target="_blank">','</a>','<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">','</a>' ); |
|
211 | + ?> |
|
212 | 212 | </span> |
213 | 213 | </div> |
214 | 214 |
@@ -12,80 +12,80 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Items { |
14 | 14 | |
15 | - /** |
|
16 | - * Submission items. |
|
17 | - * @var GetPaid_Form_Item[] |
|
18 | - */ |
|
19 | - public $items = array(); |
|
15 | + /** |
|
16 | + * Submission items. |
|
17 | + * @var GetPaid_Form_Item[] |
|
18 | + */ |
|
19 | + public $items = array(); |
|
20 | + |
|
21 | + /** |
|
22 | + * Class constructor |
|
23 | + * |
|
24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
25 | + */ |
|
26 | + public function __construct( $submission ) { |
|
27 | + |
|
28 | + $data = $submission->get_data(); |
|
29 | + $payment_form = $submission->get_payment_form(); |
|
30 | + |
|
31 | + // Prepare the selected items. |
|
32 | + $selected_items = array(); |
|
33 | + if ( ! empty( $data['getpaid-items'] ) ) { |
|
34 | + $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
35 | + } |
|
36 | + |
|
37 | + // For default forms, ensure that an item has been set. |
|
38 | + if ( $payment_form->is_default() && ( ! $submission->has_invoice() || 'payment_form' == $submission->get_invoice()->get_created_via() ) && isset( $data['getpaid-form-items'] ) ) { |
|
39 | + $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
40 | + $payment_form->set_items( getpaid_convert_items_to_array( $form_items ) ); |
|
41 | + } |
|
42 | + |
|
43 | + // Process each individual item. |
|
44 | + foreach ( $payment_form->get_items() as $item ) { |
|
45 | + $this->process_item( $item, $selected_items, $submission ); |
|
46 | + } |
|
47 | + |
|
48 | + } |
|
20 | 49 | |
21 | 50 | /** |
22 | - * Class constructor |
|
23 | - * |
|
24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
25 | - */ |
|
26 | - public function __construct( $submission ) { |
|
27 | - |
|
28 | - $data = $submission->get_data(); |
|
29 | - $payment_form = $submission->get_payment_form(); |
|
30 | - |
|
31 | - // Prepare the selected items. |
|
32 | - $selected_items = array(); |
|
33 | - if ( ! empty( $data['getpaid-items'] ) ) { |
|
34 | - $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
35 | - } |
|
36 | - |
|
37 | - // For default forms, ensure that an item has been set. |
|
38 | - if ( $payment_form->is_default() && ( ! $submission->has_invoice() || 'payment_form' == $submission->get_invoice()->get_created_via() ) && isset( $data['getpaid-form-items'] ) ) { |
|
39 | - $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
40 | - $payment_form->set_items( getpaid_convert_items_to_array( $form_items ) ); |
|
41 | - } |
|
42 | - |
|
43 | - // Process each individual item. |
|
44 | - foreach ( $payment_form->get_items() as $item ) { |
|
45 | - $this->process_item( $item, $selected_items, $submission ); |
|
46 | - } |
|
47 | - |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Process a single item. |
|
52 | - * |
|
53 | - * @param GetPaid_Form_Item $item |
|
54 | - * @param array $selected_items |
|
55 | - * @param GetPaid_Payment_Form_Submission $submission |
|
56 | - */ |
|
57 | - public function process_item( $item, $selected_items, $submission ) { |
|
58 | - |
|
59 | - // Abort if this is an optional item and it has not been selected. |
|
60 | - if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
61 | - return; |
|
62 | - } |
|
63 | - |
|
64 | - // (maybe) let customers change the quantities and prices. |
|
65 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
66 | - |
|
67 | - // Maybe change the quantities. |
|
68 | - if ( $item->allows_quantities() ) { |
|
69 | - $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
70 | - } |
|
71 | - |
|
72 | - // Maybe change the price. |
|
73 | - if ( $item->user_can_set_their_price() ) { |
|
74 | - $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
75 | - |
|
76 | - if ( $item->get_minimum_price() > $price ) { |
|
77 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), wpinv_sanitize_amount( $item->get_minimum_price() ) ) ); |
|
78 | - } |
|
79 | - |
|
80 | - $item->set_price( $price ); |
|
81 | - |
|
82 | - } |
|
83 | - |
|
84 | - } |
|
85 | - |
|
86 | - // Save the item. |
|
87 | - $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission ); |
|
88 | - |
|
89 | - } |
|
51 | + * Process a single item. |
|
52 | + * |
|
53 | + * @param GetPaid_Form_Item $item |
|
54 | + * @param array $selected_items |
|
55 | + * @param GetPaid_Payment_Form_Submission $submission |
|
56 | + */ |
|
57 | + public function process_item( $item, $selected_items, $submission ) { |
|
58 | + |
|
59 | + // Abort if this is an optional item and it has not been selected. |
|
60 | + if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
61 | + return; |
|
62 | + } |
|
63 | + |
|
64 | + // (maybe) let customers change the quantities and prices. |
|
65 | + if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
66 | + |
|
67 | + // Maybe change the quantities. |
|
68 | + if ( $item->allows_quantities() ) { |
|
69 | + $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
70 | + } |
|
71 | + |
|
72 | + // Maybe change the price. |
|
73 | + if ( $item->user_can_set_their_price() ) { |
|
74 | + $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
75 | + |
|
76 | + if ( $item->get_minimum_price() > $price ) { |
|
77 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), wpinv_sanitize_amount( $item->get_minimum_price() ) ) ); |
|
78 | + } |
|
79 | + |
|
80 | + $item->set_price( $price ); |
|
81 | + |
|
82 | + } |
|
83 | + |
|
84 | + } |
|
85 | + |
|
86 | + // Save the item. |
|
87 | + $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission ); |
|
88 | + |
|
89 | + } |
|
90 | 90 | |
91 | 91 | } |