@@ -1,32 +1,32 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | - // Is the request set up correctly? |
|
4 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
5 | - return aui()->alert( |
|
6 | - array( |
|
7 | - 'type' => 'warning', |
|
8 | - 'content' => __( 'No payment form or item selected', 'invoicing' ), |
|
9 | - ) |
|
10 | - ); |
|
11 | - wp_die( esc_html__( 'No payment form or item selected', 'invoicing' ), 400 ); |
|
12 | - } |
|
13 | - |
|
14 | - // Payment form or button? |
|
15 | - if ( ! empty( $_GET['form'] ) ) { |
|
16 | - |
|
17 | - $shortcode = sprintf( |
|
18 | - '[getpaid form=%s]', |
|
19 | - (int) $_GET['form'] |
|
20 | - ); |
|
21 | - |
|
22 | - } else { |
|
23 | - |
|
24 | - $shortcode = sprintf( |
|
25 | - '[getpaid item=%s]', |
|
26 | - esc_attr( urldecode( $_GET['item'] ) ) |
|
27 | - ); |
|
28 | - |
|
29 | - } |
|
3 | + // Is the request set up correctly? |
|
4 | + if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
5 | + return aui()->alert( |
|
6 | + array( |
|
7 | + 'type' => 'warning', |
|
8 | + 'content' => __( 'No payment form or item selected', 'invoicing' ), |
|
9 | + ) |
|
10 | + ); |
|
11 | + wp_die( esc_html__( 'No payment form or item selected', 'invoicing' ), 400 ); |
|
12 | + } |
|
13 | + |
|
14 | + // Payment form or button? |
|
15 | + if ( ! empty( $_GET['form'] ) ) { |
|
16 | + |
|
17 | + $shortcode = sprintf( |
|
18 | + '[getpaid form=%s]', |
|
19 | + (int) $_GET['form'] |
|
20 | + ); |
|
21 | + |
|
22 | + } else { |
|
23 | + |
|
24 | + $shortcode = sprintf( |
|
25 | + '[getpaid item=%s]', |
|
26 | + esc_attr( urldecode( $_GET['item'] ) ) |
|
27 | + ); |
|
28 | + |
|
29 | + } |
|
30 | 30 | |
31 | 31 | ?> |
32 | 32 | |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | |
45 | 45 | <title><?php echo esc_html( get_bloginfo( 'name' ) ); ?></title> |
46 | 46 | <?php |
47 | - wp_enqueue_scripts(); |
|
48 | - wp_print_styles(); |
|
49 | - wp_print_head_scripts(); |
|
50 | - wp_custom_css_cb(); |
|
51 | - wpinv_get_template( 'frontend-head.php' ); |
|
52 | - wp_site_icon(); |
|
53 | - ?> |
|
47 | + wp_enqueue_scripts(); |
|
48 | + wp_print_styles(); |
|
49 | + wp_print_head_scripts(); |
|
50 | + wp_custom_css_cb(); |
|
51 | + wpinv_get_template( 'frontend-head.php' ); |
|
52 | + wp_site_icon(); |
|
53 | + ?> |
|
54 | 54 | |
55 | 55 | <style type="text/css"> |
56 | 56 | .body{ |
@@ -84,11 +84,11 @@ discard block |
||
84 | 84 | <body class="body page-template-default page"> |
85 | 85 | <div id="getpaid-form-embed" class="container my-5 page type-page status-publish hentry post post-content"> |
86 | 86 | <?php |
87 | - do_action( 'getpaid_payment_form_embed_top' ); |
|
88 | - echo do_shortcode( $shortcode ); |
|
89 | - do_action( 'getpaid_payment_form_embed_bottom' ); |
|
90 | - wpinv_get_template( 'frontend-footer.php' ); |
|
91 | - ?> |
|
87 | + do_action( 'getpaid_payment_form_embed_top' ); |
|
88 | + echo do_shortcode( $shortcode ); |
|
89 | + do_action( 'getpaid_payment_form_embed_bottom' ); |
|
90 | + wpinv_get_template( 'frontend-footer.php' ); |
|
91 | + ?> |
|
92 | 92 | </div> |
93 | 93 | <?php wp_footer(); ?> |
94 | 94 | </body> |
@@ -1,18 +1,18 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Is the request set up correctly? |
4 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
4 | + if (empty($_GET['form']) && empty($_GET['item'])) { |
|
5 | 5 | return aui()->alert( |
6 | 6 | array( |
7 | 7 | 'type' => 'warning', |
8 | - 'content' => __( 'No payment form or item selected', 'invoicing' ), |
|
8 | + 'content' => __('No payment form or item selected', 'invoicing'), |
|
9 | 9 | ) |
10 | 10 | ); |
11 | - wp_die( esc_html__( 'No payment form or item selected', 'invoicing' ), 400 ); |
|
11 | + wp_die(esc_html__('No payment form or item selected', 'invoicing'), 400); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | // Payment form or button? |
15 | - if ( ! empty( $_GET['form'] ) ) { |
|
15 | + if (!empty($_GET['form'])) { |
|
16 | 16 | |
17 | 17 | $shortcode = sprintf( |
18 | 18 | '[getpaid form=%s]', |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | |
24 | 24 | $shortcode = sprintf( |
25 | 25 | '[getpaid item=%s]', |
26 | - esc_attr( urldecode( $_GET['item'] ) ) |
|
26 | + esc_attr(urldecode($_GET['item'])) |
|
27 | 27 | ); |
28 | 28 | |
29 | 29 | } |
@@ -35,20 +35,20 @@ discard block |
||
35 | 35 | |
36 | 36 | <head> |
37 | 37 | |
38 | - <meta charset="<?php bloginfo( 'charset' ); ?>"> |
|
38 | + <meta charset="<?php bloginfo('charset'); ?>"> |
|
39 | 39 | <meta name="viewport" content="width=device-width, initial-scale=1.0" > |
40 | 40 | |
41 | 41 | <meta name="robots" content="noindex,nofollow"> |
42 | 42 | |
43 | 43 | <link rel="profile" href="https://gmpg.org/xfn/11"> |
44 | 44 | |
45 | - <title><?php echo esc_html( get_bloginfo( 'name' ) ); ?></title> |
|
45 | + <title><?php echo esc_html(get_bloginfo('name')); ?></title> |
|
46 | 46 | <?php |
47 | 47 | wp_enqueue_scripts(); |
48 | 48 | wp_print_styles(); |
49 | 49 | wp_print_head_scripts(); |
50 | 50 | wp_custom_css_cb(); |
51 | - wpinv_get_template( 'frontend-head.php' ); |
|
51 | + wpinv_get_template('frontend-head.php'); |
|
52 | 52 | wp_site_icon(); |
53 | 53 | ?> |
54 | 54 | |
@@ -84,10 +84,10 @@ discard block |
||
84 | 84 | <body class="body page-template-default page"> |
85 | 85 | <div id="getpaid-form-embed" class="container my-5 page type-page status-publish hentry post post-content"> |
86 | 86 | <?php |
87 | - do_action( 'getpaid_payment_form_embed_top' ); |
|
88 | - echo do_shortcode( $shortcode ); |
|
89 | - do_action( 'getpaid_payment_form_embed_bottom' ); |
|
90 | - wpinv_get_template( 'frontend-footer.php' ); |
|
87 | + do_action('getpaid_payment_form_embed_top'); |
|
88 | + echo do_shortcode($shortcode); |
|
89 | + do_action('getpaid_payment_form_embed_bottom'); |
|
90 | + wpinv_get_template('frontend-footer.php'); |
|
91 | 91 | ?> |
92 | 92 | </div> |
93 | 93 | <?php wp_footer(); ?> |
@@ -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'] ); |
@@ -182,14 +182,14 @@ discard block |
||
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
185 | - * Retrieves a customer profile. |
|
186 | - * |
|
187 | - * |
|
188 | - * @param string $profile_id profile id. |
|
189 | - * @return string|WP_Error Profile id. |
|
185 | + * Retrieves a customer profile. |
|
186 | + * |
|
187 | + * |
|
188 | + * @param string $profile_id profile id. |
|
189 | + * @return string|WP_Error Profile id. |
|
190 | 190 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
191 | - */ |
|
192 | - public function get_customer_profile( $profile_id ) { |
|
191 | + */ |
|
192 | + public function get_customer_profile( $profile_id ) { |
|
193 | 193 | |
194 | 194 | // Generate args. |
195 | 195 | $args = array( |
@@ -204,17 +204,17 @@ discard block |
||
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
207 | - * Creates a customer profile. |
|
208 | - * |
|
209 | - * |
|
207 | + * Creates a customer profile. |
|
208 | + * |
|
209 | + * |
|
210 | 210 | * @param string $profile_id profile id. |
211 | - * @param WPInv_Invoice $invoice Invoice. |
|
211 | + * @param WPInv_Invoice $invoice Invoice. |
|
212 | 212 | * @param array $submission_data Posted checkout fields. |
213 | 213 | * @param bool $save Whether or not to save the payment as a token. |
214 | 214 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
215 | - * @return string|WP_Error Profile id. |
|
216 | - */ |
|
217 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
215 | + * @return string|WP_Error Profile id. |
|
216 | + */ |
|
217 | + public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
218 | 218 | |
219 | 219 | // Remove non-digits from the number |
220 | 220 | $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -302,13 +302,13 @@ discard block |
||
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
305 | - * Retrieves payment details from cache. |
|
306 | - * |
|
307 | - * |
|
305 | + * Retrieves payment details from cache. |
|
306 | + * |
|
307 | + * |
|
308 | 308 | * @param array $payment_details. |
309 | - * @return array|false Profile id. |
|
310 | - */ |
|
311 | - public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
309 | + * @return array|false Profile id. |
|
310 | + */ |
|
311 | + public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
312 | 312 | |
313 | 313 | $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
314 | 314 | $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
@@ -333,13 +333,13 @@ discard block |
||
333 | 333 | } |
334 | 334 | |
335 | 335 | /** |
336 | - * Securely adds payment details to cache. |
|
337 | - * |
|
338 | - * |
|
336 | + * Securely adds payment details to cache. |
|
337 | + * |
|
338 | + * |
|
339 | 339 | * @param array $payment_details. |
340 | 340 | * @param string $payment_profile_id. |
341 | - */ |
|
342 | - public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
341 | + */ |
|
342 | + public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
343 | 343 | |
344 | 344 | $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
345 | 345 | $cached_information = is_array( $cached_information ) ? $cached_information : array(); |
@@ -351,15 +351,15 @@ discard block |
||
351 | 351 | } |
352 | 352 | |
353 | 353 | /** |
354 | - * Retrieves a customer payment profile. |
|
355 | - * |
|
356 | - * |
|
357 | - * @param string $customer_profile_id customer profile id. |
|
354 | + * Retrieves a customer payment profile. |
|
355 | + * |
|
356 | + * |
|
357 | + * @param string $customer_profile_id customer profile id. |
|
358 | 358 | * @param string $payment_profile_id payment profile id. |
359 | - * @return string|WP_Error Profile id. |
|
359 | + * @return string|WP_Error Profile id. |
|
360 | 360 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
361 | - */ |
|
362 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
361 | + */ |
|
362 | + public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
363 | 363 | |
364 | 364 | // Generate args. |
365 | 365 | $args = array( |
@@ -375,15 +375,15 @@ discard block |
||
375 | 375 | } |
376 | 376 | |
377 | 377 | /** |
378 | - * Charges a customer payment profile. |
|
379 | - * |
|
378 | + * Charges a customer payment profile. |
|
379 | + * |
|
380 | 380 | * @param string $customer_profile_id customer profile id. |
381 | 381 | * @param string $payment_profile_id payment profile id. |
382 | - * @param WPInv_Invoice $invoice Invoice. |
|
382 | + * @param WPInv_Invoice $invoice Invoice. |
|
383 | 383 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
384 | - * @return WP_Error|object |
|
385 | - */ |
|
386 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
384 | + * @return WP_Error|object |
|
385 | + */ |
|
386 | + public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
387 | 387 | |
388 | 388 | // Generate args. |
389 | 389 | $args = array( |
@@ -429,41 +429,41 @@ discard block |
||
429 | 429 | } |
430 | 430 | |
431 | 431 | /** |
432 | - * Processes a customer charge. |
|
433 | - * |
|
432 | + * Processes a customer charge. |
|
433 | + * |
|
434 | 434 | * @param stdClass $result Api response. |
435 | - * @param WPInv_Invoice $invoice Invoice. |
|
436 | - */ |
|
437 | - public function process_charge_response( $result, $invoice ) { |
|
435 | + * @param WPInv_Invoice $invoice Invoice. |
|
436 | + */ |
|
437 | + public function process_charge_response( $result, $invoice ) { |
|
438 | 438 | |
439 | 439 | wpinv_clear_errors(); |
440 | - $response_code = (int) $result->transactionResponse->responseCode; |
|
440 | + $response_code = (int) $result->transactionResponse->responseCode; |
|
441 | 441 | |
442 | - // Succeeded. |
|
443 | - if ( 1 == $response_code || 4 == $response_code ) { |
|
442 | + // Succeeded. |
|
443 | + if ( 1 == $response_code || 4 == $response_code ) { |
|
444 | 444 | |
445 | - // Maybe set a transaction id. |
|
446 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
447 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
448 | - } |
|
445 | + // Maybe set a transaction id. |
|
446 | + if ( ! empty( $result->transactionResponse->transId ) ) { |
|
447 | + $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
448 | + } |
|
449 | 449 | |
450 | - $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
450 | + $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
451 | 451 | |
452 | - if ( 1 == $response_code ) { |
|
453 | - return $invoice->mark_paid(); |
|
454 | - } |
|
452 | + if ( 1 == $response_code ) { |
|
453 | + return $invoice->mark_paid(); |
|
454 | + } |
|
455 | 455 | |
456 | - $invoice->set_status( 'wpi-onhold' ); |
|
457 | - $invoice->add_note( |
|
456 | + $invoice->set_status( 'wpi-onhold' ); |
|
457 | + $invoice->add_note( |
|
458 | 458 | sprintf( |
459 | 459 | __( 'Held for review: %s', 'invoicing' ), |
460 | 460 | $result->transactionResponse->messages->message[0]->description |
461 | 461 | ) |
462 | - ); |
|
462 | + ); |
|
463 | 463 | |
464 | - return $invoice->save(); |
|
464 | + return $invoice->save(); |
|
465 | 465 | |
466 | - } |
|
466 | + } |
|
467 | 467 | |
468 | 468 | wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) ); |
469 | 469 | |
@@ -475,13 +475,13 @@ discard block |
||
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
478 | - * Returns payment information. |
|
479 | - * |
|
480 | - * |
|
481 | - * @param array $card Card details. |
|
482 | - * @return array |
|
483 | - */ |
|
484 | - public function get_payment_information( $card ) { |
|
478 | + * Returns payment information. |
|
479 | + * |
|
480 | + * |
|
481 | + * @param array $card Card details. |
|
482 | + * @return array |
|
483 | + */ |
|
484 | + public function get_payment_information( $card ) { |
|
485 | 485 | return array( |
486 | 486 | |
487 | 487 | 'creditCard' => array( |
@@ -494,25 +494,25 @@ discard block |
||
494 | 494 | } |
495 | 495 | |
496 | 496 | /** |
497 | - * Returns the customer profile meta name. |
|
498 | - * |
|
499 | - * |
|
500 | - * @param WPInv_Invoice $invoice Invoice. |
|
501 | - * @return string |
|
502 | - */ |
|
503 | - public function get_customer_profile_meta_name( $invoice ) { |
|
497 | + * Returns the customer profile meta name. |
|
498 | + * |
|
499 | + * |
|
500 | + * @param WPInv_Invoice $invoice Invoice. |
|
501 | + * @return string |
|
502 | + */ |
|
503 | + public function get_customer_profile_meta_name( $invoice ) { |
|
504 | 504 | return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
505 | 505 | } |
506 | 506 | |
507 | 507 | /** |
508 | - * Validates the submitted data. |
|
509 | - * |
|
510 | - * |
|
511 | - * @param array $submission_data Posted checkout fields. |
|
508 | + * Validates the submitted data. |
|
509 | + * |
|
510 | + * |
|
511 | + * @param array $submission_data Posted checkout fields. |
|
512 | 512 | * @param WPInv_Invoice $invoice |
513 | - * @return WP_Error|string The payment profile id |
|
514 | - */ |
|
515 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
513 | + * @return WP_Error|string The payment profile id |
|
514 | + */ |
|
515 | + public function validate_submission_data( $submission_data, $invoice ) { |
|
516 | 516 | |
517 | 517 | // Validate authentication details. |
518 | 518 | $auth = $this->get_auth_params(); |
@@ -544,13 +544,13 @@ discard block |
||
544 | 544 | } |
545 | 545 | |
546 | 546 | /** |
547 | - * Returns invoice line items. |
|
548 | - * |
|
549 | - * |
|
550 | - * @param WPInv_Invoice $invoice Invoice. |
|
551 | - * @return array |
|
552 | - */ |
|
553 | - public function get_line_items( $invoice ) { |
|
547 | + * Returns invoice line items. |
|
548 | + * |
|
549 | + * |
|
550 | + * @param WPInv_Invoice $invoice Invoice. |
|
551 | + * @return array |
|
552 | + */ |
|
553 | + public function get_line_items( $invoice ) { |
|
554 | 554 | $items = array(); |
555 | 555 | |
556 | 556 | foreach ( $invoice->get_items() as $item ) { |
@@ -587,15 +587,15 @@ discard block |
||
587 | 587 | } |
588 | 588 | |
589 | 589 | /** |
590 | - * Process Payment. |
|
591 | - * |
|
592 | - * |
|
593 | - * @param WPInv_Invoice $invoice Invoice. |
|
594 | - * @param array $submission_data Posted checkout fields. |
|
595 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
596 | - * @return array |
|
597 | - */ |
|
598 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
590 | + * Process Payment. |
|
591 | + * |
|
592 | + * |
|
593 | + * @param WPInv_Invoice $invoice Invoice. |
|
594 | + * @param array $submission_data Posted checkout fields. |
|
595 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
596 | + * @return array |
|
597 | + */ |
|
598 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
599 | 599 | |
600 | 600 | // Validate the submitted data. |
601 | 601 | $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
@@ -628,45 +628,45 @@ discard block |
||
628 | 628 | |
629 | 629 | exit; |
630 | 630 | |
631 | - } |
|
631 | + } |
|
632 | 632 | |
633 | - /** |
|
634 | - * Processes the initial payment. |
|
635 | - * |
|
633 | + /** |
|
634 | + * Processes the initial payment. |
|
635 | + * |
|
636 | 636 | * @param WPInv_Invoice $invoice Invoice. |
637 | - */ |
|
638 | - protected function process_initial_payment( $invoice ) { |
|
637 | + */ |
|
638 | + protected function process_initial_payment( $invoice ) { |
|
639 | 639 | |
640 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
640 | + $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
641 | 641 | $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
642 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
642 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
643 | 643 | |
644 | - // Do we have an error? |
|
645 | - if ( is_wp_error( $result ) ) { |
|
646 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
647 | - wpinv_send_back_to_checkout( $invoice ); |
|
648 | - } |
|
644 | + // Do we have an error? |
|
645 | + if ( is_wp_error( $result ) ) { |
|
646 | + wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
647 | + wpinv_send_back_to_checkout( $invoice ); |
|
648 | + } |
|
649 | 649 | |
650 | - // Process the response. |
|
651 | - $this->process_charge_response( $result, $invoice ); |
|
650 | + // Process the response. |
|
651 | + $this->process_charge_response( $result, $invoice ); |
|
652 | 652 | |
653 | - if ( wpinv_get_errors() ) { |
|
654 | - wpinv_send_back_to_checkout( $invoice ); |
|
655 | - } |
|
653 | + if ( wpinv_get_errors() ) { |
|
654 | + wpinv_send_back_to_checkout( $invoice ); |
|
655 | + } |
|
656 | 656 | |
657 | - } |
|
657 | + } |
|
658 | 658 | |
659 | 659 | /** |
660 | - * Processes recurring payments. |
|
661 | - * |
|
660 | + * Processes recurring payments. |
|
661 | + * |
|
662 | 662 | * @param WPInv_Invoice $invoice Invoice. |
663 | 663 | * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions. |
664 | - */ |
|
665 | - public function process_subscription( $invoice, $subscriptions ) { |
|
664 | + */ |
|
665 | + public function process_subscription( $invoice, $subscriptions ) { |
|
666 | 666 | |
667 | 667 | // Check if there is an initial amount to charge. |
668 | 668 | if ( (float) $invoice->get_total() > 0 ) { |
669 | - $this->process_initial_payment( $invoice ); |
|
669 | + $this->process_initial_payment( $invoice ); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | // Activate the subscriptions. |
@@ -684,36 +684,36 @@ discard block |
||
684 | 684 | } |
685 | 685 | } |
686 | 686 | |
687 | - // Redirect to the success page. |
|
687 | + // Redirect to the success page. |
|
688 | 688 | wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
689 | 689 | |
690 | 690 | } |
691 | 691 | |
692 | - /** |
|
693 | - * (Maybe) renews an authorize.net subscription profile. |
|
694 | - * |
|
695 | - * |
|
692 | + /** |
|
693 | + * (Maybe) renews an authorize.net subscription profile. |
|
694 | + * |
|
695 | + * |
|
696 | 696 | * @param WPInv_Subscription $subscription |
697 | - */ |
|
698 | - public function maybe_renew_subscription( $subscription ) { |
|
697 | + */ |
|
698 | + public function maybe_renew_subscription( $subscription ) { |
|
699 | 699 | |
700 | 700 | // Ensure its our subscription && it's active. |
701 | 701 | if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
702 | 702 | $this->renew_subscription( $subscription ); |
703 | 703 | } |
704 | 704 | |
705 | - } |
|
705 | + } |
|
706 | 706 | |
707 | 707 | /** |
708 | - * Renews a subscription. |
|
709 | - * |
|
708 | + * Renews a subscription. |
|
709 | + * |
|
710 | 710 | * @param WPInv_Subscription $subscription |
711 | - */ |
|
712 | - public function renew_subscription( $subscription ) { |
|
711 | + */ |
|
712 | + public function renew_subscription( $subscription ) { |
|
713 | 713 | |
714 | - // Generate the renewal invoice. |
|
715 | - $new_invoice = $subscription->create_payment(); |
|
716 | - $old_invoice = $subscription->get_parent_payment(); |
|
714 | + // Generate the renewal invoice. |
|
715 | + $new_invoice = $subscription->create_payment(); |
|
716 | + $old_invoice = $subscription->get_parent_payment(); |
|
717 | 717 | |
718 | 718 | if ( empty( $new_invoice ) ) { |
719 | 719 | $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
@@ -722,37 +722,37 @@ discard block |
||
722 | 722 | } |
723 | 723 | |
724 | 724 | // Charge the payment method. |
725 | - $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
726 | - $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
727 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
728 | - |
|
729 | - // Do we have an error? |
|
730 | - if ( is_wp_error( $result ) ) { |
|
731 | - |
|
732 | - $old_invoice->add_note( |
|
733 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
734 | - true, |
|
735 | - false, |
|
736 | - true |
|
737 | - ); |
|
738 | - $subscription->failing(); |
|
739 | - return; |
|
740 | - |
|
741 | - } |
|
742 | - |
|
743 | - // Process the response. |
|
744 | - $this->process_charge_response( $result, $new_invoice ); |
|
745 | - |
|
746 | - if ( wpinv_get_errors() ) { |
|
747 | - |
|
748 | - $old_invoice->add_note( |
|
749 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
750 | - true, |
|
751 | - false, |
|
752 | - true |
|
753 | - ); |
|
754 | - $subscription->failing(); |
|
755 | - return; |
|
725 | + $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
726 | + $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
727 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
728 | + |
|
729 | + // Do we have an error? |
|
730 | + if ( is_wp_error( $result ) ) { |
|
731 | + |
|
732 | + $old_invoice->add_note( |
|
733 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
734 | + true, |
|
735 | + false, |
|
736 | + true |
|
737 | + ); |
|
738 | + $subscription->failing(); |
|
739 | + return; |
|
740 | + |
|
741 | + } |
|
742 | + |
|
743 | + // Process the response. |
|
744 | + $this->process_charge_response( $result, $new_invoice ); |
|
745 | + |
|
746 | + if ( wpinv_get_errors() ) { |
|
747 | + |
|
748 | + $old_invoice->add_note( |
|
749 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
750 | + true, |
|
751 | + false, |
|
752 | + true |
|
753 | + ); |
|
754 | + $subscription->failing(); |
|
755 | + return; |
|
756 | 756 | |
757 | 757 | } |
758 | 758 | |
@@ -761,13 +761,13 @@ discard block |
||
761 | 761 | } |
762 | 762 | |
763 | 763 | /** |
764 | - * Processes invoice addons. |
|
765 | - * |
|
766 | - * @param WPInv_Invoice $invoice |
|
767 | - * @param GetPaid_Form_Item[] $items |
|
768 | - * @return WPInv_Invoice |
|
769 | - */ |
|
770 | - public function process_addons( $invoice, $items ) { |
|
764 | + * Processes invoice addons. |
|
765 | + * |
|
766 | + * @param WPInv_Invoice $invoice |
|
767 | + * @param GetPaid_Form_Item[] $items |
|
768 | + * @return WPInv_Invoice |
|
769 | + */ |
|
770 | + public function process_addons( $invoice, $items ) { |
|
771 | 771 | |
772 | 772 | global $getpaid_authorize_addons; |
773 | 773 | |
@@ -786,7 +786,7 @@ discard block |
||
786 | 786 | $invoice->recalculate_total(); |
787 | 787 | |
788 | 788 | $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
789 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
789 | + $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
790 | 790 | |
791 | 791 | add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 ); |
792 | 792 | $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
@@ -801,11 +801,11 @@ discard block |
||
801 | 801 | } |
802 | 802 | |
803 | 803 | /** |
804 | - * Processes invoice addons. |
|
805 | - * |
|
804 | + * Processes invoice addons. |
|
805 | + * |
|
806 | 806 | * @param array $args |
807 | - * @return array |
|
808 | - */ |
|
807 | + * @return array |
|
808 | + */ |
|
809 | 809 | public function filter_addons_request( $args ) { |
810 | 810 | |
811 | 811 | global $getpaid_authorize_addons; |
@@ -839,11 +839,11 @@ discard block |
||
839 | 839 | } |
840 | 840 | |
841 | 841 | /** |
842 | - * Filters the gateway settings. |
|
843 | - * |
|
844 | - * @param array $admin_settings |
|
845 | - */ |
|
846 | - public function admin_settings( $admin_settings ) { |
|
842 | + * Filters the gateway settings. |
|
843 | + * |
|
844 | + * @param array $admin_settings |
|
845 | + */ |
|
846 | + public function admin_settings( $admin_settings ) { |
|
847 | 847 | |
848 | 848 | $currencies = sprintf( |
849 | 849 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -883,7 +883,7 @@ discard block |
||
883 | 883 | 'readonly' => true, |
884 | 884 | ); |
885 | 885 | |
886 | - return $admin_settings; |
|
887 | - } |
|
886 | + return $admin_settings; |
|
887 | + } |
|
888 | 888 | |
889 | 889 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Authorize.net Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
27 | + protected $supports = array('subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @var array |
54 | 54 | */ |
55 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
55 | + public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD'); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * URL to view a transaction. |
@@ -66,12 +66,12 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function __construct() { |
68 | 68 | |
69 | - $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
|
70 | - $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
|
71 | - $this->notify_url = getpaid_get_non_query_string_ipn_url( $this->id ); |
|
69 | + $this->title = __('Credit Card / Debit Card', 'invoicing'); |
|
70 | + $this->method_title = __('Authorize.Net', 'invoicing'); |
|
71 | + $this->notify_url = getpaid_get_non_query_string_ipn_url($this->id); |
|
72 | 72 | |
73 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
74 | - add_filter( 'getpaid_authorizenet_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
73 | + add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription')); |
|
74 | + add_filter('getpaid_authorizenet_sandbox_notice', array($this, 'sandbox_notice')); |
|
75 | 75 | parent::__construct(); |
76 | 76 | } |
77 | 77 | |
@@ -81,13 +81,13 @@ discard block |
||
81 | 81 | * @param int $invoice_id 0 or invoice id. |
82 | 82 | * @param GetPaid_Payment_Form $form Current payment form. |
83 | 83 | */ |
84 | - public function payment_fields( $invoice_id, $form ) { |
|
84 | + public function payment_fields($invoice_id, $form) { |
|
85 | 85 | |
86 | 86 | // Let the user select a payment method. |
87 | 87 | $this->saved_payment_methods(); |
88 | 88 | |
89 | 89 | // Show the credit card entry form. |
90 | - $this->new_payment_method_entry( $this->get_cc_form( true ) ); |
|
90 | + $this->new_payment_method_entry($this->get_cc_form(true)); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -100,79 +100,79 @@ discard block |
||
100 | 100 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
101 | 101 | * @return string|WP_Error Payment profile id. |
102 | 102 | */ |
103 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
103 | + public function create_customer_profile($invoice, $submission_data, $save = true) { |
|
104 | 104 | |
105 | 105 | // Remove non-digits from the number |
106 | - $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
106 | + $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
107 | 107 | |
108 | 108 | // Generate args. |
109 | 109 | $args = array( |
110 | 110 | 'createCustomerProfileRequest' => array( |
111 | 111 | 'merchantAuthentication' => $this->get_auth_params(), |
112 | 112 | 'profile' => array( |
113 | - 'merchantCustomerId' => getpaid_limit_length( $invoice->get_user_id(), 20 ), |
|
114 | - 'description' => getpaid_limit_length( $invoice->get_full_name(), 255 ), |
|
115 | - 'email' => getpaid_limit_length( $invoice->get_email(), 255 ), |
|
113 | + 'merchantCustomerId' => getpaid_limit_length($invoice->get_user_id(), 20), |
|
114 | + 'description' => getpaid_limit_length($invoice->get_full_name(), 255), |
|
115 | + 'email' => getpaid_limit_length($invoice->get_email(), 255), |
|
116 | 116 | 'paymentProfiles' => array( |
117 | 117 | 'customerType' => 'individual', |
118 | 118 | |
119 | 119 | // Billing information. |
120 | 120 | 'billTo' => array( |
121 | - 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
122 | - 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
123 | - 'address' => getpaid_limit_length( $invoice->get_address(), 60 ), |
|
124 | - 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
125 | - 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
126 | - 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
127 | - 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
121 | + 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
122 | + 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
123 | + 'address' => getpaid_limit_length($invoice->get_address(), 60), |
|
124 | + 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
125 | + 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
126 | + 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
127 | + 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
128 | 128 | ), |
129 | 129 | |
130 | 130 | // Payment information. |
131 | - 'payment' => $this->get_payment_information( $submission_data['authorizenet'] ), |
|
131 | + 'payment' => $this->get_payment_information($submission_data['authorizenet']), |
|
132 | 132 | ), |
133 | 133 | ), |
134 | - 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
134 | + 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
135 | 135 | ), |
136 | 136 | ); |
137 | 137 | |
138 | - $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice ); |
|
138 | + $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice); |
|
139 | 139 | |
140 | - if ( is_wp_error( $response ) ) { |
|
140 | + if (is_wp_error($response)) { |
|
141 | 141 | |
142 | 142 | // In case the payment profile already exists remotely. |
143 | - if ( 'dup_payment_profile' === $response->get_error_code() ) { |
|
144 | - $customer_profile_id = strtok( $response->get_error_message(), '.' ); |
|
145 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile_id ); |
|
146 | - return strtok( '.' ); |
|
143 | + if ('dup_payment_profile' === $response->get_error_code()) { |
|
144 | + $customer_profile_id = strtok($response->get_error_message(), '.'); |
|
145 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile_id); |
|
146 | + return strtok('.'); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | // In case the customer profile already exists remotely. |
150 | - if ( 'E00039' === $response->get_error_code() ) { |
|
151 | - $customer_profile_id = str_replace( 'A duplicate record with ID ', '', $response->get_error_message() ); |
|
152 | - $customer_profile_id = str_replace( ' already exists.', '', $customer_profile_id ); |
|
153 | - return $this->create_customer_payment_profile( trim( $customer_profile_id ), $invoice, $submission_data, $save ); |
|
150 | + if ('E00039' === $response->get_error_code()) { |
|
151 | + $customer_profile_id = str_replace('A duplicate record with ID ', '', $response->get_error_message()); |
|
152 | + $customer_profile_id = str_replace(' already exists.', '', $customer_profile_id); |
|
153 | + return $this->create_customer_payment_profile(trim($customer_profile_id), $invoice, $submission_data, $save); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | return $response; |
157 | 157 | } |
158 | 158 | |
159 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId ); |
|
159 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId); |
|
160 | 160 | |
161 | 161 | // Save the payment token. |
162 | - if ( $save ) { |
|
162 | + if ($save) { |
|
163 | 163 | $this->save_token( |
164 | 164 | array( |
165 | 165 | 'id' => $response->customerPaymentProfileIdList[0], |
166 | - 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . '····' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
166 | + 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . '····' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
167 | 167 | 'default' => true, |
168 | - 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
168 | + 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
169 | 169 | ) |
170 | 170 | ); |
171 | 171 | } |
172 | 172 | |
173 | 173 | // Add a note about the validation response. |
174 | 174 | $invoice->add_note( |
175 | - sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ), |
|
175 | + sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]), |
|
176 | 176 | false, |
177 | 177 | false, |
178 | 178 | true |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * @return string|WP_Error Profile id. |
190 | 190 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
191 | 191 | */ |
192 | - public function get_customer_profile( $profile_id ) { |
|
192 | + public function get_customer_profile($profile_id) { |
|
193 | 193 | |
194 | 194 | // Generate args. |
195 | 195 | $args = array( |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | ), |
200 | 200 | ); |
201 | 201 | |
202 | - return $this->post( $args, false ); |
|
202 | + return $this->post($args, false); |
|
203 | 203 | |
204 | 204 | } |
205 | 205 | |
@@ -214,18 +214,18 @@ discard block |
||
214 | 214 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
215 | 215 | * @return string|WP_Error Profile id. |
216 | 216 | */ |
217 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
217 | + public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) { |
|
218 | 218 | |
219 | 219 | // Remove non-digits from the number |
220 | - $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
220 | + $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
221 | 221 | |
222 | 222 | // Prepare card details. |
223 | - $payment_information = $this->get_payment_information( $submission_data['authorizenet'] ); |
|
223 | + $payment_information = $this->get_payment_information($submission_data['authorizenet']); |
|
224 | 224 | |
225 | 225 | // Authorize.NET does not support saving the same card twice. |
226 | - $cached_information = $this->retrieve_payment_profile_from_cache( $payment_information, $customer_profile, $invoice ); |
|
226 | + $cached_information = $this->retrieve_payment_profile_from_cache($payment_information, $customer_profile, $invoice); |
|
227 | 227 | |
228 | - if ( $cached_information ) { |
|
228 | + if ($cached_information) { |
|
229 | 229 | return $cached_information; |
230 | 230 | } |
231 | 231 | |
@@ -238,34 +238,34 @@ discard block |
||
238 | 238 | |
239 | 239 | // Billing information. |
240 | 240 | 'billTo' => array( |
241 | - 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
242 | - 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
243 | - 'address' => getpaid_limit_length( $invoice->get_address(), 60 ), |
|
244 | - 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
245 | - 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
246 | - 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
247 | - 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
241 | + 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
242 | + 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
243 | + 'address' => getpaid_limit_length($invoice->get_address(), 60), |
|
244 | + 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
245 | + 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
246 | + 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
247 | + 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
248 | 248 | ), |
249 | 249 | |
250 | 250 | // Payment information. |
251 | 251 | 'payment' => $payment_information, |
252 | 252 | ), |
253 | - 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
253 | + 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
254 | 254 | ), |
255 | 255 | ); |
256 | 256 | |
257 | - $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
257 | + $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice); |
|
258 | 258 | |
259 | - if ( is_wp_error( $response ) ) { |
|
259 | + if (is_wp_error($response)) { |
|
260 | 260 | |
261 | 261 | // In case the payment profile already exists remotely. |
262 | - if ( 'dup_payment_profile' == $response->get_error_code() ) { |
|
263 | - $customer_profile_id = strtok( $response->get_error_message(), '.' ); |
|
264 | - $payment_profile_id = strtok( '.' ); |
|
265 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile_id ); |
|
262 | + if ('dup_payment_profile' == $response->get_error_code()) { |
|
263 | + $customer_profile_id = strtok($response->get_error_message(), '.'); |
|
264 | + $payment_profile_id = strtok('.'); |
|
265 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile_id); |
|
266 | 266 | |
267 | 267 | // Cache payment profile id. |
268 | - $this->add_payment_profile_to_cache( $payment_information, $payment_profile_id ); |
|
268 | + $this->add_payment_profile_to_cache($payment_information, $payment_profile_id); |
|
269 | 269 | |
270 | 270 | return $payment_profile_id; |
271 | 271 | } |
@@ -274,29 +274,29 @@ discard block |
||
274 | 274 | } |
275 | 275 | |
276 | 276 | // Save the payment token. |
277 | - if ( $save ) { |
|
277 | + if ($save) { |
|
278 | 278 | $this->save_token( |
279 | 279 | array( |
280 | 280 | 'id' => $response->customerPaymentProfileId, |
281 | - 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' ···· ' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
281 | + 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . ' ···· ' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
282 | 282 | 'default' => true, |
283 | - 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
283 | + 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
284 | 284 | ) |
285 | 285 | ); |
286 | 286 | } |
287 | 287 | |
288 | 288 | // Cache payment profile id. |
289 | - $this->add_payment_profile_to_cache( $payment_information, $response->customerPaymentProfileId ); |
|
289 | + $this->add_payment_profile_to_cache($payment_information, $response->customerPaymentProfileId); |
|
290 | 290 | |
291 | 291 | // Add a note about the validation response. |
292 | 292 | $invoice->add_note( |
293 | - sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ), |
|
293 | + sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse), |
|
294 | 294 | false, |
295 | 295 | false, |
296 | 296 | true |
297 | 297 | ); |
298 | 298 | |
299 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile ); |
|
299 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile); |
|
300 | 300 | |
301 | 301 | return $response->customerPaymentProfileId; |
302 | 302 | } |
@@ -308,12 +308,12 @@ discard block |
||
308 | 308 | * @param array $payment_details. |
309 | 309 | * @return array|false Profile id. |
310 | 310 | */ |
311 | - public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
311 | + public function retrieve_payment_profile_from_cache($payment_details, $customer_profile, $invoice) { |
|
312 | 312 | |
313 | - $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
|
314 | - $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
|
313 | + $cached_information = get_option('getpaid_authorize_net_cached_profiles', array()); |
|
314 | + $payment_details = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY); |
|
315 | 315 | |
316 | - if ( ! is_array( $cached_information ) || ! array_key_exists( $payment_details, $cached_information ) ) { |
|
316 | + if (!is_array($cached_information) || !array_key_exists($payment_details, $cached_information)) { |
|
317 | 317 | return false; |
318 | 318 | } |
319 | 319 | |
@@ -322,13 +322,13 @@ discard block |
||
322 | 322 | 'getCustomerPaymentProfileRequest' => array( |
323 | 323 | 'merchantAuthentication' => $this->get_auth_params(), |
324 | 324 | 'customerProfileId' => $customer_profile, |
325 | - 'customerPaymentProfileId' => $cached_information[ $payment_details ], |
|
325 | + 'customerPaymentProfileId' => $cached_information[$payment_details], |
|
326 | 326 | ), |
327 | 327 | ); |
328 | 328 | |
329 | - $response = $this->post( $args, $invoice ); |
|
329 | + $response = $this->post($args, $invoice); |
|
330 | 330 | |
331 | - return is_wp_error( $response ) ? false : $cached_information[ $payment_details ]; |
|
331 | + return is_wp_error($response) ? false : $cached_information[$payment_details]; |
|
332 | 332 | |
333 | 333 | } |
334 | 334 | |
@@ -339,14 +339,14 @@ discard block |
||
339 | 339 | * @param array $payment_details. |
340 | 340 | * @param string $payment_profile_id. |
341 | 341 | */ |
342 | - public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
342 | + public function add_payment_profile_to_cache($payment_details, $payment_profile_id) { |
|
343 | 343 | |
344 | - $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
|
345 | - $cached_information = is_array( $cached_information ) ? $cached_information : array(); |
|
346 | - $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
|
344 | + $cached_information = get_option('getpaid_authorize_net_cached_profiles', array()); |
|
345 | + $cached_information = is_array($cached_information) ? $cached_information : array(); |
|
346 | + $payment_details = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY); |
|
347 | 347 | |
348 | - $cached_information[ $payment_details ] = $payment_profile_id; |
|
349 | - update_option( 'getpaid_authorize_net_cached_profiles', $cached_information ); |
|
348 | + $cached_information[$payment_details] = $payment_profile_id; |
|
349 | + update_option('getpaid_authorize_net_cached_profiles', $cached_information); |
|
350 | 350 | |
351 | 351 | } |
352 | 352 | |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | * @return string|WP_Error Profile id. |
360 | 360 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
361 | 361 | */ |
362 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
362 | + public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) { |
|
363 | 363 | |
364 | 364 | // Generate args. |
365 | 365 | $args = array( |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | ), |
371 | 371 | ); |
372 | 372 | |
373 | - return $this->post( $args, false ); |
|
373 | + return $this->post($args, false); |
|
374 | 374 | |
375 | 375 | } |
376 | 376 | |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
384 | 384 | * @return WP_Error|object |
385 | 385 | */ |
386 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
386 | + public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) { |
|
387 | 387 | |
388 | 388 | // Generate args. |
389 | 389 | $args = array( |
@@ -403,28 +403,28 @@ discard block |
||
403 | 403 | ), |
404 | 404 | ), |
405 | 405 | 'order' => array( |
406 | - 'invoiceNumber' => getpaid_limit_length( $invoice->get_number(), 20 ), |
|
406 | + 'invoiceNumber' => getpaid_limit_length($invoice->get_number(), 20), |
|
407 | 407 | ), |
408 | - 'lineItems' => array( 'lineItem' => $this->get_line_items( $invoice ) ), |
|
408 | + 'lineItems' => array('lineItem' => $this->get_line_items($invoice)), |
|
409 | 409 | 'tax' => array( |
410 | 410 | 'amount' => $invoice->get_total_tax(), |
411 | - 'name' => __( 'TAX', 'invoicing' ), |
|
411 | + 'name' => __('TAX', 'invoicing'), |
|
412 | 412 | ), |
413 | - 'poNumber' => getpaid_limit_length( $invoice->get_number(), 25 ), |
|
413 | + 'poNumber' => getpaid_limit_length($invoice->get_number(), 25), |
|
414 | 414 | 'customer' => array( |
415 | - 'id' => getpaid_limit_length( $invoice->get_user_id(), 25 ), |
|
416 | - 'email' => getpaid_limit_length( $invoice->get_email(), 25 ), |
|
415 | + 'id' => getpaid_limit_length($invoice->get_user_id(), 25), |
|
416 | + 'email' => getpaid_limit_length($invoice->get_email(), 25), |
|
417 | 417 | ), |
418 | 418 | 'customerIP' => $invoice->get_ip(), |
419 | 419 | ), |
420 | 420 | ), |
421 | 421 | ); |
422 | 422 | |
423 | - if ( 0 == $invoice->get_total_tax() ) { |
|
424 | - unset( $args['createTransactionRequest']['transactionRequest']['tax'] ); |
|
423 | + if (0 == $invoice->get_total_tax()) { |
|
424 | + unset($args['createTransactionRequest']['transactionRequest']['tax']); |
|
425 | 425 | } |
426 | 426 | |
427 | - return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
427 | + return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice); |
|
428 | 428 | |
429 | 429 | } |
430 | 430 | |
@@ -434,29 +434,29 @@ discard block |
||
434 | 434 | * @param stdClass $result Api response. |
435 | 435 | * @param WPInv_Invoice $invoice Invoice. |
436 | 436 | */ |
437 | - public function process_charge_response( $result, $invoice ) { |
|
437 | + public function process_charge_response($result, $invoice) { |
|
438 | 438 | |
439 | 439 | wpinv_clear_errors(); |
440 | 440 | $response_code = (int) $result->transactionResponse->responseCode; |
441 | 441 | |
442 | 442 | // Succeeded. |
443 | - if ( 1 == $response_code || 4 == $response_code ) { |
|
443 | + if (1 == $response_code || 4 == $response_code) { |
|
444 | 444 | |
445 | 445 | // Maybe set a transaction id. |
446 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
447 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
446 | + if (!empty($result->transactionResponse->transId)) { |
|
447 | + $invoice->set_transaction_id($result->transactionResponse->transId); |
|
448 | 448 | } |
449 | 449 | |
450 | - $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
450 | + $invoice->add_note(sprintf(__('Authentication code: %1$s (%2$s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true); |
|
451 | 451 | |
452 | - if ( 1 == $response_code ) { |
|
452 | + if (1 == $response_code) { |
|
453 | 453 | return $invoice->mark_paid(); |
454 | 454 | } |
455 | 455 | |
456 | - $invoice->set_status( 'wpi-onhold' ); |
|
456 | + $invoice->set_status('wpi-onhold'); |
|
457 | 457 | $invoice->add_note( |
458 | 458 | sprintf( |
459 | - __( 'Held for review: %s', 'invoicing' ), |
|
459 | + __('Held for review: %s', 'invoicing'), |
|
460 | 460 | $result->transactionResponse->messages->message[0]->description |
461 | 461 | ) |
462 | 462 | ); |
@@ -465,11 +465,11 @@ discard block |
||
465 | 465 | |
466 | 466 | } |
467 | 467 | |
468 | - wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) ); |
|
468 | + wpinv_set_error('card_declined', __('Credit card declined.', 'invoicing')); |
|
469 | 469 | |
470 | - if ( ! empty( $result->transactionResponse->errors ) ) { |
|
470 | + if (!empty($result->transactionResponse->errors)) { |
|
471 | 471 | $errors = (object) $result->transactionResponse->errors; |
472 | - wpinv_set_error( $errors->error[0]->errorCode, esc_html( $errors->error[0]->errorText ) ); |
|
472 | + wpinv_set_error($errors->error[0]->errorCode, esc_html($errors->error[0]->errorText)); |
|
473 | 473 | } |
474 | 474 | |
475 | 475 | } |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | * @param array $card Card details. |
482 | 482 | * @return array |
483 | 483 | */ |
484 | - public function get_payment_information( $card ) { |
|
484 | + public function get_payment_information($card) { |
|
485 | 485 | return array( |
486 | 486 | |
487 | 487 | 'creditCard' => array( |
@@ -500,8 +500,8 @@ discard block |
||
500 | 500 | * @param WPInv_Invoice $invoice Invoice. |
501 | 501 | * @return string |
502 | 502 | */ |
503 | - public function get_customer_profile_meta_name( $invoice ) { |
|
504 | - return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
503 | + public function get_customer_profile_meta_name($invoice) { |
|
504 | + return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
505 | 505 | } |
506 | 506 | |
507 | 507 | /** |
@@ -512,34 +512,34 @@ discard block |
||
512 | 512 | * @param WPInv_Invoice $invoice |
513 | 513 | * @return WP_Error|string The payment profile id |
514 | 514 | */ |
515 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
515 | + public function validate_submission_data($submission_data, $invoice) { |
|
516 | 516 | |
517 | 517 | // Validate authentication details. |
518 | 518 | $auth = $this->get_auth_params(); |
519 | 519 | |
520 | - if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) { |
|
521 | - return new WP_Error( 'invalid_settings', __( 'Please set-up your login id and transaction key before using this gateway.', 'invoicing' ) ); |
|
520 | + if (empty($auth['name']) || empty($auth['transactionKey'])) { |
|
521 | + return new WP_Error('invalid_settings', __('Please set-up your login id and transaction key before using this gateway.', 'invoicing')); |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | // Validate the payment method. |
525 | - if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) { |
|
526 | - return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing' ) ); |
|
525 | + if (empty($submission_data['getpaid-authorizenet-payment-method'])) { |
|
526 | + return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing')); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | // Are we adding a new payment method? |
530 | - if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) { |
|
530 | + if ('new' != $submission_data['getpaid-authorizenet-payment-method']) { |
|
531 | 531 | return $submission_data['getpaid-authorizenet-payment-method']; |
532 | 532 | } |
533 | 533 | |
534 | 534 | // Retrieve the customer profile id. |
535 | - $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
535 | + $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
536 | 536 | |
537 | 537 | // Create payment method. |
538 | - if ( empty( $profile_id ) ) { |
|
539 | - return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
538 | + if (empty($profile_id)) { |
|
539 | + return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
540 | 540 | } |
541 | 541 | |
542 | - return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
542 | + return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
543 | 543 | |
544 | 544 | } |
545 | 545 | |
@@ -550,32 +550,32 @@ discard block |
||
550 | 550 | * @param WPInv_Invoice $invoice Invoice. |
551 | 551 | * @return array |
552 | 552 | */ |
553 | - public function get_line_items( $invoice ) { |
|
553 | + public function get_line_items($invoice) { |
|
554 | 554 | $items = array(); |
555 | 555 | |
556 | - foreach ( $invoice->get_items() as $item ) { |
|
556 | + foreach ($invoice->get_items() as $item) { |
|
557 | 557 | |
558 | 558 | $amount = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price(); |
559 | 559 | $items[] = array( |
560 | - 'itemId' => getpaid_limit_length( $item->get_id(), 31 ), |
|
561 | - 'name' => getpaid_limit_length( $item->get_raw_name(), 31 ), |
|
562 | - 'description' => getpaid_limit_length( $item->get_description(), 255 ), |
|
563 | - 'quantity' => (string) ( $invoice->get_template() == 'amount' ? 1 : $item->get_quantity() ), |
|
560 | + 'itemId' => getpaid_limit_length($item->get_id(), 31), |
|
561 | + 'name' => getpaid_limit_length($item->get_raw_name(), 31), |
|
562 | + 'description' => getpaid_limit_length($item->get_description(), 255), |
|
563 | + 'quantity' => (string) ($invoice->get_template() == 'amount' ? 1 : $item->get_quantity()), |
|
564 | 564 | 'unitPrice' => (float) $amount, |
565 | 565 | 'taxable' => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(), |
566 | 566 | ); |
567 | 567 | |
568 | 568 | } |
569 | 569 | |
570 | - foreach ( $invoice->get_fees() as $fee_name => $fee ) { |
|
570 | + foreach ($invoice->get_fees() as $fee_name => $fee) { |
|
571 | 571 | |
572 | - $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee']; |
|
572 | + $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee']; |
|
573 | 573 | |
574 | - if ( $amount > 0 ) { |
|
574 | + if ($amount > 0) { |
|
575 | 575 | $items[] = array( |
576 | - 'itemId' => getpaid_limit_length( $fee_name, 31 ), |
|
577 | - 'name' => getpaid_limit_length( $fee_name, 31 ), |
|
578 | - 'description' => getpaid_limit_length( $fee_name, 255 ), |
|
576 | + 'itemId' => getpaid_limit_length($fee_name, 31), |
|
577 | + 'name' => getpaid_limit_length($fee_name, 31), |
|
578 | + 'description' => getpaid_limit_length($fee_name, 255), |
|
579 | 579 | 'quantity' => '1', |
580 | 580 | 'unitPrice' => (float) $amount, |
581 | 581 | 'taxable' => false, |
@@ -595,36 +595,36 @@ discard block |
||
595 | 595 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
596 | 596 | * @return array |
597 | 597 | */ |
598 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
598 | + public function process_payment($invoice, $submission_data, $submission) { |
|
599 | 599 | |
600 | 600 | // Validate the submitted data. |
601 | - $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
|
601 | + $payment_profile_id = $this->validate_submission_data($submission_data, $invoice); |
|
602 | 602 | |
603 | 603 | // Do we have an error? |
604 | - if ( is_wp_error( $payment_profile_id ) ) { |
|
605 | - wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() ); |
|
606 | - wpinv_send_back_to_checkout( $invoice ); |
|
604 | + if (is_wp_error($payment_profile_id)) { |
|
605 | + wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message()); |
|
606 | + wpinv_send_back_to_checkout($invoice); |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | // Save the payment method to the order. |
610 | - update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id ); |
|
610 | + update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id); |
|
611 | 611 | |
612 | 612 | // Check if this is a subscription or not. |
613 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
614 | - if ( ! empty( $subscriptions ) ) { |
|
615 | - $this->process_subscription( $invoice, $subscriptions ); |
|
613 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
614 | + if (!empty($subscriptions)) { |
|
615 | + $this->process_subscription($invoice, $subscriptions); |
|
616 | 616 | } |
617 | 617 | |
618 | 618 | // If it is free, send to the success page. |
619 | - if ( ! $invoice->needs_payment() ) { |
|
619 | + if (!$invoice->needs_payment()) { |
|
620 | 620 | $invoice->mark_paid(); |
621 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
621 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | // Charge the payment profile. |
625 | - $this->process_initial_payment( $invoice ); |
|
625 | + $this->process_initial_payment($invoice); |
|
626 | 626 | |
627 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
627 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
628 | 628 | |
629 | 629 | exit; |
630 | 630 | |
@@ -635,23 +635,23 @@ discard block |
||
635 | 635 | * |
636 | 636 | * @param WPInv_Invoice $invoice Invoice. |
637 | 637 | */ |
638 | - protected function process_initial_payment( $invoice ) { |
|
638 | + protected function process_initial_payment($invoice) { |
|
639 | 639 | |
640 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
641 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
642 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
640 | + $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
641 | + $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
642 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
643 | 643 | |
644 | 644 | // Do we have an error? |
645 | - if ( is_wp_error( $result ) ) { |
|
646 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
647 | - wpinv_send_back_to_checkout( $invoice ); |
|
645 | + if (is_wp_error($result)) { |
|
646 | + wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
647 | + wpinv_send_back_to_checkout($invoice); |
|
648 | 648 | } |
649 | 649 | |
650 | 650 | // Process the response. |
651 | - $this->process_charge_response( $result, $invoice ); |
|
651 | + $this->process_charge_response($result, $invoice); |
|
652 | 652 | |
653 | - if ( wpinv_get_errors() ) { |
|
654 | - wpinv_send_back_to_checkout( $invoice ); |
|
653 | + if (wpinv_get_errors()) { |
|
654 | + wpinv_send_back_to_checkout($invoice); |
|
655 | 655 | } |
656 | 656 | |
657 | 657 | } |
@@ -662,30 +662,30 @@ discard block |
||
662 | 662 | * @param WPInv_Invoice $invoice Invoice. |
663 | 663 | * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions. |
664 | 664 | */ |
665 | - public function process_subscription( $invoice, $subscriptions ) { |
|
665 | + public function process_subscription($invoice, $subscriptions) { |
|
666 | 666 | |
667 | 667 | // Check if there is an initial amount to charge. |
668 | - if ( (float) $invoice->get_total() > 0 ) { |
|
669 | - $this->process_initial_payment( $invoice ); |
|
668 | + if ((float) $invoice->get_total() > 0) { |
|
669 | + $this->process_initial_payment($invoice); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | // Activate the subscriptions. |
673 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
673 | + $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions); |
|
674 | 674 | |
675 | - foreach ( $subscriptions as $subscription ) { |
|
676 | - if ( $subscription->exists() ) { |
|
677 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
678 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
675 | + foreach ($subscriptions as $subscription) { |
|
676 | + if ($subscription->exists()) { |
|
677 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
678 | + $expiry = date('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
679 | 679 | |
680 | - $subscription->set_next_renewal_date( $expiry ); |
|
681 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
682 | - $subscription->set_profile_id( $invoice->generate_key( 'authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ) ); |
|
680 | + $subscription->set_next_renewal_date($expiry); |
|
681 | + $subscription->set_date_created(current_time('mysql')); |
|
682 | + $subscription->set_profile_id($invoice->generate_key('authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id())); |
|
683 | 683 | $subscription->activate(); |
684 | 684 | } |
685 | 685 | } |
686 | 686 | |
687 | 687 | // Redirect to the success page. |
688 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
688 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
689 | 689 | |
690 | 690 | } |
691 | 691 | |
@@ -695,11 +695,11 @@ discard block |
||
695 | 695 | * |
696 | 696 | * @param WPInv_Subscription $subscription |
697 | 697 | */ |
698 | - public function maybe_renew_subscription( $subscription ) { |
|
698 | + public function maybe_renew_subscription($subscription) { |
|
699 | 699 | |
700 | 700 | // Ensure its our subscription && it's active. |
701 | - if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
702 | - $this->renew_subscription( $subscription ); |
|
701 | + if ($this->id === $subscription->get_gateway() && $subscription->has_status('active trialling')) { |
|
702 | + $this->renew_subscription($subscription); |
|
703 | 703 | } |
704 | 704 | |
705 | 705 | } |
@@ -709,28 +709,28 @@ discard block |
||
709 | 709 | * |
710 | 710 | * @param WPInv_Subscription $subscription |
711 | 711 | */ |
712 | - public function renew_subscription( $subscription ) { |
|
712 | + public function renew_subscription($subscription) { |
|
713 | 713 | |
714 | 714 | // Generate the renewal invoice. |
715 | 715 | $new_invoice = $subscription->create_payment(); |
716 | 716 | $old_invoice = $subscription->get_parent_payment(); |
717 | 717 | |
718 | - if ( empty( $new_invoice ) ) { |
|
719 | - $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
|
718 | + if (empty($new_invoice)) { |
|
719 | + $old_invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false); |
|
720 | 720 | $subscription->failing(); |
721 | 721 | return; |
722 | 722 | } |
723 | 723 | |
724 | 724 | // Charge the payment method. |
725 | - $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
726 | - $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
727 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
725 | + $payment_profile_id = get_post_meta($old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
726 | + $customer_profile = get_user_meta($old_invoice->get_user_id(), $this->get_customer_profile_meta_name($old_invoice), true); |
|
727 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice); |
|
728 | 728 | |
729 | 729 | // Do we have an error? |
730 | - if ( is_wp_error( $result ) ) { |
|
730 | + if (is_wp_error($result)) { |
|
731 | 731 | |
732 | 732 | $old_invoice->add_note( |
733 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
733 | + sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()), |
|
734 | 734 | true, |
735 | 735 | false, |
736 | 736 | true |
@@ -741,12 +741,12 @@ discard block |
||
741 | 741 | } |
742 | 742 | |
743 | 743 | // Process the response. |
744 | - $this->process_charge_response( $result, $new_invoice ); |
|
744 | + $this->process_charge_response($result, $new_invoice); |
|
745 | 745 | |
746 | - if ( wpinv_get_errors() ) { |
|
746 | + if (wpinv_get_errors()) { |
|
747 | 747 | |
748 | 748 | $old_invoice->add_note( |
749 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
749 | + sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()), |
|
750 | 750 | true, |
751 | 751 | false, |
752 | 752 | true |
@@ -756,7 +756,7 @@ discard block |
||
756 | 756 | |
757 | 757 | } |
758 | 758 | |
759 | - $subscription->add_payment( array(), $new_invoice ); |
|
759 | + $subscription->add_payment(array(), $new_invoice); |
|
760 | 760 | $subscription->renew(); |
761 | 761 | } |
762 | 762 | |
@@ -767,33 +767,33 @@ discard block |
||
767 | 767 | * @param GetPaid_Form_Item[] $items |
768 | 768 | * @return WPInv_Invoice |
769 | 769 | */ |
770 | - public function process_addons( $invoice, $items ) { |
|
770 | + public function process_addons($invoice, $items) { |
|
771 | 771 | |
772 | 772 | global $getpaid_authorize_addons; |
773 | 773 | |
774 | 774 | $getpaid_authorize_addons = array(); |
775 | - foreach ( $items as $item ) { |
|
775 | + foreach ($items as $item) { |
|
776 | 776 | |
777 | - if ( is_null( $invoice->get_item( $item->get_id() ) ) && ! is_wp_error( $invoice->add_item( $item ) ) ) { |
|
777 | + if (is_null($invoice->get_item($item->get_id())) && !is_wp_error($invoice->add_item($item))) { |
|
778 | 778 | $getpaid_authorize_addons[] = $item; |
779 | 779 | } |
780 | 780 | } |
781 | 781 | |
782 | - if ( empty( $getpaid_authorize_addons ) ) { |
|
782 | + if (empty($getpaid_authorize_addons)) { |
|
783 | 783 | return; |
784 | 784 | } |
785 | 785 | |
786 | 786 | $invoice->recalculate_total(); |
787 | 787 | |
788 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
789 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
788 | + $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
789 | + $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
790 | 790 | |
791 | - add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 ); |
|
792 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
793 | - remove_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ) ); |
|
791 | + add_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'), 10, 2); |
|
792 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
793 | + remove_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request')); |
|
794 | 794 | |
795 | - if ( is_wp_error( $result ) ) { |
|
796 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
795 | + if (is_wp_error($result)) { |
|
796 | + wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
797 | 797 | return; |
798 | 798 | } |
799 | 799 | |
@@ -806,19 +806,19 @@ discard block |
||
806 | 806 | * @param array $args |
807 | 807 | * @return array |
808 | 808 | */ |
809 | - public function filter_addons_request( $args ) { |
|
809 | + public function filter_addons_request($args) { |
|
810 | 810 | |
811 | 811 | global $getpaid_authorize_addons; |
812 | 812 | $total = 0; |
813 | 813 | |
814 | - foreach ( $getpaid_authorize_addons as $addon ) { |
|
814 | + foreach ($getpaid_authorize_addons as $addon) { |
|
815 | 815 | $total += $addon->get_sub_total(); |
816 | 816 | } |
817 | 817 | |
818 | 818 | $args['createTransactionRequest']['transactionRequest']['amount'] = $total; |
819 | 819 | |
820 | - if ( isset( $args['createTransactionRequest']['transactionRequest']['tax'] ) ) { |
|
821 | - unset( $args['createTransactionRequest']['transactionRequest']['tax'] ); |
|
820 | + if (isset($args['createTransactionRequest']['transactionRequest']['tax'])) { |
|
821 | + unset($args['createTransactionRequest']['transactionRequest']['tax']); |
|
822 | 822 | } |
823 | 823 | |
824 | 824 | return $args; |
@@ -831,7 +831,7 @@ discard block |
||
831 | 831 | public function sandbox_notice() { |
832 | 832 | |
833 | 833 | return sprintf( |
834 | - __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %1$sAuthorize.NET Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
834 | + __('SANDBOX ENABLED. You can use sandbox testing details only. See the %1$sAuthorize.NET Sandbox Testing Guide%2$s for more details.', 'invoicing'), |
|
835 | 835 | '<a href="https://developer.authorize.net/hello_world/testing_guide.html">', |
836 | 836 | '</a>' |
837 | 837 | ); |
@@ -843,42 +843,42 @@ discard block |
||
843 | 843 | * |
844 | 844 | * @param array $admin_settings |
845 | 845 | */ |
846 | - public function admin_settings( $admin_settings ) { |
|
846 | + public function admin_settings($admin_settings) { |
|
847 | 847 | |
848 | 848 | $currencies = sprintf( |
849 | - __( 'Supported Currencies: %s', 'invoicing' ), |
|
850 | - implode( ', ', $this->currencies ) |
|
849 | + __('Supported Currencies: %s', 'invoicing'), |
|
850 | + implode(', ', $this->currencies) |
|
851 | 851 | ); |
852 | 852 | |
853 | 853 | $admin_settings['authorizenet_active']['desc'] .= " ($currencies)"; |
854 | - $admin_settings['authorizenet_desc']['std'] = __( 'Pay securely using your credit or debit card.', 'invoicing' ); |
|
854 | + $admin_settings['authorizenet_desc']['std'] = __('Pay securely using your credit or debit card.', 'invoicing'); |
|
855 | 855 | |
856 | 856 | $admin_settings['authorizenet_login_id'] = array( |
857 | 857 | 'type' => 'text', |
858 | 858 | 'id' => 'authorizenet_login_id', |
859 | - 'name' => __( 'API Login ID', 'invoicing' ), |
|
860 | - 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __( 'How do I obtain my API Login ID and Transaction Key?', 'invoicing' ) . '</em></a>', |
|
859 | + 'name' => __('API Login ID', 'invoicing'), |
|
860 | + 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __('How do I obtain my API Login ID and Transaction Key?', 'invoicing') . '</em></a>', |
|
861 | 861 | ); |
862 | 862 | |
863 | 863 | $admin_settings['authorizenet_transaction_key'] = array( |
864 | 864 | 'type' => 'text', |
865 | 865 | 'id' => 'authorizenet_transaction_key', |
866 | - 'name' => __( 'Transaction Key', 'invoicing' ), |
|
866 | + 'name' => __('Transaction Key', 'invoicing'), |
|
867 | 867 | ); |
868 | 868 | |
869 | 869 | $admin_settings['authorizenet_signature_key'] = array( |
870 | 870 | 'type' => 'text', |
871 | 871 | 'id' => 'authorizenet_signature_key', |
872 | - 'name' => __( 'Signature Key', 'invoicing' ), |
|
873 | - 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
872 | + 'name' => __('Signature Key', 'invoicing'), |
|
873 | + 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
874 | 874 | ); |
875 | 875 | |
876 | 876 | $admin_settings['authorizenet_ipn_url'] = array( |
877 | 877 | 'type' => 'ipn_url', |
878 | 878 | 'id' => 'authorizenet_ipn_url', |
879 | - 'name' => __( 'Webhook URL', 'invoicing' ), |
|
879 | + 'name' => __('Webhook URL', 'invoicing'), |
|
880 | 880 | 'std' => $this->notify_url, |
881 | - 'desc' => __( 'Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing' ) . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
881 | + 'desc' => __('Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing') . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
882 | 882 | 'custom' => 'authorizenet', |
883 | 883 | 'readonly' => true, |
884 | 884 | ); |
@@ -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(); |
@@ -84,12 +84,12 @@ discard block |
||
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
87 | - * (Maybe) renews a manual subscription profile. |
|
88 | - * |
|
89 | - * |
|
87 | + * (Maybe) renews a manual subscription profile. |
|
88 | + * |
|
89 | + * |
|
90 | 90 | * @param WPInv_Subscription $subscription |
91 | - */ |
|
92 | - public function maybe_renew_subscription( $subscription ) { |
|
91 | + */ |
|
92 | + public function maybe_renew_subscription( $subscription ) { |
|
93 | 93 | |
94 | 94 | // Ensure its our subscription && it's active. |
95 | 95 | if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
@@ -109,13 +109,13 @@ discard block |
||
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
112 | - * Processes invoice addons. |
|
113 | - * |
|
114 | - * @param WPInv_Invoice $invoice |
|
115 | - * @param GetPaid_Form_Item[] $items |
|
116 | - * @return WPInv_Invoice |
|
117 | - */ |
|
118 | - public function process_addons( $invoice, $items ) { |
|
112 | + * Processes invoice addons. |
|
113 | + * |
|
114 | + * @param WPInv_Invoice $invoice |
|
115 | + * @param GetPaid_Form_Item[] $items |
|
116 | + * @return WPInv_Invoice |
|
117 | + */ |
|
118 | + public function process_addons( $invoice, $items ) { |
|
119 | 119 | |
120 | 120 | foreach ( $items as $item ) { |
121 | 121 | $invoice->add_item( $item ); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Manual Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
27 | + protected $supports = array('subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -39,10 +39,10 @@ discard block |
||
39 | 39 | public function __construct() { |
40 | 40 | parent::__construct(); |
41 | 41 | |
42 | - $this->title = __( 'Test Gateway', 'invoicing' ); |
|
43 | - $this->method_title = __( 'Test Gateway', 'invoicing' ); |
|
42 | + $this->title = __('Test Gateway', 'invoicing'); |
|
43 | + $this->method_title = __('Test Gateway', 'invoicing'); |
|
44 | 44 | |
45 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
45 | + add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription')); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -54,32 +54,32 @@ discard block |
||
54 | 54 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
55 | 55 | * @return array |
56 | 56 | */ |
57 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
57 | + public function process_payment($invoice, $submission_data, $submission) { |
|
58 | 58 | |
59 | 59 | // Mark it as paid. |
60 | 60 | $invoice->mark_paid(); |
61 | 61 | |
62 | 62 | // (Maybe) activate subscriptions. |
63 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
63 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
64 | 64 | |
65 | - if ( ! empty( $subscriptions ) ) { |
|
66 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
65 | + if (!empty($subscriptions)) { |
|
66 | + $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions); |
|
67 | 67 | |
68 | - foreach ( $subscriptions as $subscription ) { |
|
69 | - if ( $subscription->exists() ) { |
|
70 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
71 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
68 | + foreach ($subscriptions as $subscription) { |
|
69 | + if ($subscription->exists()) { |
|
70 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
71 | + $expiry = date('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
72 | 72 | |
73 | - $subscription->set_next_renewal_date( $expiry ); |
|
74 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
75 | - $subscription->set_profile_id( $invoice->generate_key( 'manual_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ) ); |
|
73 | + $subscription->set_next_renewal_date($expiry); |
|
74 | + $subscription->set_date_created(current_time('mysql')); |
|
75 | + $subscription->set_profile_id($invoice->generate_key('manual_sub_' . $invoice->get_id() . '_' . $subscription->get_id())); |
|
76 | 76 | $subscription->activate(); |
77 | 77 | } |
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
81 | 81 | // Send to the success page. |
82 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
82 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
83 | 83 | |
84 | 84 | } |
85 | 85 | |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @param WPInv_Subscription $subscription |
91 | 91 | */ |
92 | - public function maybe_renew_subscription( $subscription ) { |
|
92 | + public function maybe_renew_subscription($subscription) { |
|
93 | 93 | |
94 | 94 | // Ensure its our subscription && it's active. |
95 | - if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
95 | + if ($this->id === $subscription->get_gateway() && $subscription->has_status('active trialling')) { |
|
96 | 96 | |
97 | 97 | // Renew the subscription. |
98 | 98 | $subscription->add_payment( |
@@ -115,10 +115,10 @@ discard block |
||
115 | 115 | * @param GetPaid_Form_Item[] $items |
116 | 116 | * @return WPInv_Invoice |
117 | 117 | */ |
118 | - public function process_addons( $invoice, $items ) { |
|
118 | + public function process_addons($invoice, $items) { |
|
119 | 119 | |
120 | - foreach ( $items as $item ) { |
|
121 | - $invoice->add_item( $item ); |
|
120 | + foreach ($items as $item) { |
|
121 | + $invoice->add_item($item); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | $invoice->recalculate_total(); |
@@ -13,311 +13,311 @@ |
||
13 | 13 | class GetPaid_Subscription_Notification_Emails { |
14 | 14 | |
15 | 15 | /** |
16 | - * The array of subscription email actions. |
|
17 | - * |
|
18 | - * @param array |
|
19 | - */ |
|
20 | - public $subscription_actions; |
|
16 | + * The array of subscription email actions. |
|
17 | + * |
|
18 | + * @param array |
|
19 | + */ |
|
20 | + public $subscription_actions; |
|
21 | 21 | |
22 | 22 | /** |
23 | - * Class constructor |
|
23 | + * Class constructor |
|
24 | 24 | * |
25 | - */ |
|
26 | - public function __construct() { |
|
27 | - |
|
28 | - $this->subscription_actions = apply_filters( |
|
29 | - 'getpaid_notification_email_subscription_triggers', |
|
30 | - array( |
|
31 | - 'getpaid_subscription_trialling' => 'subscription_trial', |
|
32 | - 'getpaid_subscription_cancelled' => 'subscription_cancelled', |
|
33 | - 'getpaid_subscription_expired' => 'subscription_expired', |
|
34 | - 'getpaid_subscription_completed' => 'subscription_complete', |
|
35 | - 'getpaid_daily_maintenance' => 'renewal_reminder', |
|
36 | - ) |
|
37 | - ); |
|
38 | - |
|
39 | - $this->init_hooks(); |
|
25 | + */ |
|
26 | + public function __construct() { |
|
27 | + |
|
28 | + $this->subscription_actions = apply_filters( |
|
29 | + 'getpaid_notification_email_subscription_triggers', |
|
30 | + array( |
|
31 | + 'getpaid_subscription_trialling' => 'subscription_trial', |
|
32 | + 'getpaid_subscription_cancelled' => 'subscription_cancelled', |
|
33 | + 'getpaid_subscription_expired' => 'subscription_expired', |
|
34 | + 'getpaid_subscription_completed' => 'subscription_complete', |
|
35 | + 'getpaid_daily_maintenance' => 'renewal_reminder', |
|
36 | + ) |
|
37 | + ); |
|
38 | + |
|
39 | + $this->init_hooks(); |
|
40 | 40 | |
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
44 | - * Registers email hooks. |
|
45 | - */ |
|
46 | - public function init_hooks() { |
|
47 | - |
|
48 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
49 | - foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
50 | - |
|
51 | - $email = new GetPaid_Notification_Email( $email_type ); |
|
52 | - |
|
53 | - if ( ! $email->is_active() ) { |
|
54 | - continue; |
|
55 | - } |
|
56 | - |
|
57 | - if ( method_exists( $this, $email_type ) ) { |
|
58 | - add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
59 | - continue; |
|
60 | - } |
|
61 | - |
|
62 | - do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
63 | - |
|
64 | - } |
|
65 | - |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Filters subscription merge tags. |
|
70 | - * |
|
71 | - * @param array $merge_tags |
|
72 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
73 | - */ |
|
74 | - public function subscription_merge_tags( $merge_tags, $object ) { |
|
75 | - |
|
76 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
77 | - $merge_tags = array_merge( |
|
78 | - $merge_tags, |
|
79 | - $this->get_subscription_merge_tags( $object ) |
|
80 | - ); |
|
81 | - } |
|
82 | - |
|
83 | - return $merge_tags; |
|
84 | - |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Generates subscription merge tags. |
|
89 | - * |
|
90 | - * @param WPInv_Subscription $subscription |
|
91 | - * @return array |
|
92 | - */ |
|
93 | - public function get_subscription_merge_tags( $subscription ) { |
|
94 | - |
|
95 | - // Abort if it does not exist. |
|
96 | - if ( ! $subscription->get_id() ) { |
|
97 | - return array(); |
|
98 | - } |
|
99 | - |
|
100 | - $invoice = $subscription->get_parent_invoice(); |
|
101 | - return array( |
|
102 | - '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
103 | - '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
104 | - '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
105 | - '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
106 | - '{subscription_id}' => absint( $subscription->get_id() ), |
|
107 | - '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ), |
|
108 | - '{subscription_initial_amount}' => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ), |
|
109 | - '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
110 | - '{subscription_bill_times}' => $subscription->get_bill_times(), |
|
111 | - '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
112 | - ); |
|
113 | - |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Checks if we should send a notification for a subscription. |
|
118 | - * |
|
119 | - * @param WPInv_Invoice $invoice |
|
120 | - * @return bool |
|
121 | - */ |
|
122 | - public function should_send_notification( $invoice ) { |
|
123 | - return 0 != $invoice->get_id(); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Returns notification recipients. |
|
128 | - * |
|
129 | - * @param WPInv_Invoice $invoice |
|
130 | - * @return array |
|
131 | - */ |
|
132 | - public function get_recipients( $invoice ) { |
|
133 | - $recipients = array( $invoice->get_email() ); |
|
134 | - |
|
135 | - $cc = $invoice->get_email_cc(); |
|
136 | - |
|
137 | - if ( ! empty( $cc ) ) { |
|
138 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
139 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
140 | - } |
|
141 | - |
|
142 | - return $recipients; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Helper function to send an email. |
|
147 | - * |
|
148 | - * @param WPInv_Subscription $subscription |
|
149 | - * @param GetPaid_Notification_Email $email |
|
150 | - * @param string $type |
|
151 | - * @param array $extra_args Extra template args. |
|
152 | - */ |
|
153 | - public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
154 | - |
|
155 | - if ( empty( $subscription ) ) { |
|
156 | - return; |
|
157 | - } |
|
158 | - |
|
159 | - if ( is_array( $subscription ) ) { |
|
160 | - $subscription = current( $subscription ); |
|
161 | - } |
|
162 | - |
|
163 | - if ( ! $subscription instanceof WPInv_Subscription ) { |
|
164 | - return; |
|
165 | - } |
|
166 | - |
|
167 | - // Abort in case the parent invoice does not exist. |
|
168 | - $invoice = $subscription->get_parent_invoice(); |
|
169 | - if ( ! $this->should_send_notification( $invoice ) ) { |
|
170 | - return; |
|
171 | - } |
|
172 | - |
|
173 | - if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) { |
|
174 | - return; |
|
175 | - } |
|
176 | - |
|
177 | - do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
178 | - |
|
179 | - $recipients = $this->get_recipients( $invoice ); |
|
180 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
181 | - $merge_tags = $email->get_merge_tags(); |
|
182 | - $content = $email->get_content( $merge_tags, $extra_args ); |
|
183 | - $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
184 | - $attachments = $email->get_attachments(); |
|
185 | - |
|
186 | - $result = $mailer->send( |
|
187 | - apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
188 | - $subject, |
|
189 | - $content, |
|
190 | - $attachments |
|
191 | - ); |
|
192 | - |
|
193 | - // Maybe send a copy to the admin. |
|
194 | - if ( $email->include_admin_bcc() ) { |
|
195 | - $mailer->send( |
|
196 | - wpinv_get_admin_email(), |
|
197 | - $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
198 | - $content, |
|
199 | - $attachments |
|
200 | - ); |
|
201 | - } |
|
202 | - |
|
203 | - if ( $result ) { |
|
204 | - $invoice->add_system_note( |
|
205 | - sprintf( |
|
206 | - __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
207 | - sanitize_key( $type ), |
|
208 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
209 | - ) |
|
210 | - ); |
|
211 | - } else { |
|
212 | - $invoice->add_system_note( |
|
213 | - sprintf( |
|
214 | - __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
215 | - sanitize_key( $type ), |
|
216 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
217 | - ) |
|
218 | - ); |
|
219 | - } |
|
220 | - |
|
221 | - do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
222 | - |
|
223 | - } |
|
44 | + * Registers email hooks. |
|
45 | + */ |
|
46 | + public function init_hooks() { |
|
47 | + |
|
48 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
49 | + foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
50 | + |
|
51 | + $email = new GetPaid_Notification_Email( $email_type ); |
|
52 | + |
|
53 | + if ( ! $email->is_active() ) { |
|
54 | + continue; |
|
55 | + } |
|
56 | + |
|
57 | + if ( method_exists( $this, $email_type ) ) { |
|
58 | + add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
59 | + continue; |
|
60 | + } |
|
61 | + |
|
62 | + do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
63 | + |
|
64 | + } |
|
65 | + |
|
66 | + } |
|
224 | 67 | |
225 | 68 | /** |
226 | - * Sends a new trial notification. |
|
227 | - * |
|
228 | - * @param WPInv_Subscription $subscription |
|
229 | - */ |
|
230 | - public function subscription_trial( $subscription ) { |
|
69 | + * Filters subscription merge tags. |
|
70 | + * |
|
71 | + * @param array $merge_tags |
|
72 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
73 | + */ |
|
74 | + public function subscription_merge_tags( $merge_tags, $object ) { |
|
231 | 75 | |
232 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
233 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
76 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
77 | + $merge_tags = array_merge( |
|
78 | + $merge_tags, |
|
79 | + $this->get_subscription_merge_tags( $object ) |
|
80 | + ); |
|
81 | + } |
|
234 | 82 | |
235 | - } |
|
83 | + return $merge_tags; |
|
236 | 84 | |
237 | - /** |
|
238 | - * Sends a cancelled subscription notification. |
|
239 | - * |
|
240 | - * @param WPInv_Subscription $subscription |
|
241 | - */ |
|
242 | - public function subscription_cancelled( $subscription ) { |
|
85 | + } |
|
243 | 86 | |
244 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
245 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
87 | + /** |
|
88 | + * Generates subscription merge tags. |
|
89 | + * |
|
90 | + * @param WPInv_Subscription $subscription |
|
91 | + * @return array |
|
92 | + */ |
|
93 | + public function get_subscription_merge_tags( $subscription ) { |
|
94 | + |
|
95 | + // Abort if it does not exist. |
|
96 | + if ( ! $subscription->get_id() ) { |
|
97 | + return array(); |
|
98 | + } |
|
99 | + |
|
100 | + $invoice = $subscription->get_parent_invoice(); |
|
101 | + return array( |
|
102 | + '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
103 | + '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
104 | + '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
105 | + '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
106 | + '{subscription_id}' => absint( $subscription->get_id() ), |
|
107 | + '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ), |
|
108 | + '{subscription_initial_amount}' => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ), |
|
109 | + '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
110 | + '{subscription_bill_times}' => $subscription->get_bill_times(), |
|
111 | + '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
112 | + ); |
|
246 | 113 | |
247 | - } |
|
114 | + } |
|
248 | 115 | |
249 | - /** |
|
250 | - * Sends a subscription expired notification. |
|
251 | - * |
|
252 | - * @param WPInv_Subscription $subscription |
|
253 | - */ |
|
254 | - public function subscription_expired( $subscription ) { |
|
116 | + /** |
|
117 | + * Checks if we should send a notification for a subscription. |
|
118 | + * |
|
119 | + * @param WPInv_Invoice $invoice |
|
120 | + * @return bool |
|
121 | + */ |
|
122 | + public function should_send_notification( $invoice ) { |
|
123 | + return 0 != $invoice->get_id(); |
|
124 | + } |
|
255 | 125 | |
256 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
257 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
126 | + /** |
|
127 | + * Returns notification recipients. |
|
128 | + * |
|
129 | + * @param WPInv_Invoice $invoice |
|
130 | + * @return array |
|
131 | + */ |
|
132 | + public function get_recipients( $invoice ) { |
|
133 | + $recipients = array( $invoice->get_email() ); |
|
258 | 134 | |
259 | - } |
|
135 | + $cc = $invoice->get_email_cc(); |
|
260 | 136 | |
261 | - /** |
|
262 | - * Sends a completed subscription notification. |
|
263 | - * |
|
264 | - * @param WPInv_Subscription $subscription |
|
265 | - */ |
|
266 | - public function subscription_complete( $subscription ) { |
|
137 | + if ( ! empty( $cc ) ) { |
|
138 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
139 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
140 | + } |
|
267 | 141 | |
268 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
269 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
142 | + return $recipients; |
|
143 | + } |
|
270 | 144 | |
271 | - } |
|
145 | + /** |
|
146 | + * Helper function to send an email. |
|
147 | + * |
|
148 | + * @param WPInv_Subscription $subscription |
|
149 | + * @param GetPaid_Notification_Email $email |
|
150 | + * @param string $type |
|
151 | + * @param array $extra_args Extra template args. |
|
152 | + */ |
|
153 | + public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
154 | + |
|
155 | + if ( empty( $subscription ) ) { |
|
156 | + return; |
|
157 | + } |
|
158 | + |
|
159 | + if ( is_array( $subscription ) ) { |
|
160 | + $subscription = current( $subscription ); |
|
161 | + } |
|
162 | + |
|
163 | + if ( ! $subscription instanceof WPInv_Subscription ) { |
|
164 | + return; |
|
165 | + } |
|
166 | + |
|
167 | + // Abort in case the parent invoice does not exist. |
|
168 | + $invoice = $subscription->get_parent_invoice(); |
|
169 | + if ( ! $this->should_send_notification( $invoice ) ) { |
|
170 | + return; |
|
171 | + } |
|
172 | + |
|
173 | + if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) { |
|
174 | + return; |
|
175 | + } |
|
176 | + |
|
177 | + do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
178 | + |
|
179 | + $recipients = $this->get_recipients( $invoice ); |
|
180 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
181 | + $merge_tags = $email->get_merge_tags(); |
|
182 | + $content = $email->get_content( $merge_tags, $extra_args ); |
|
183 | + $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
184 | + $attachments = $email->get_attachments(); |
|
185 | + |
|
186 | + $result = $mailer->send( |
|
187 | + apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
188 | + $subject, |
|
189 | + $content, |
|
190 | + $attachments |
|
191 | + ); |
|
192 | + |
|
193 | + // Maybe send a copy to the admin. |
|
194 | + if ( $email->include_admin_bcc() ) { |
|
195 | + $mailer->send( |
|
196 | + wpinv_get_admin_email(), |
|
197 | + $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
198 | + $content, |
|
199 | + $attachments |
|
200 | + ); |
|
201 | + } |
|
202 | + |
|
203 | + if ( $result ) { |
|
204 | + $invoice->add_system_note( |
|
205 | + sprintf( |
|
206 | + __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
207 | + sanitize_key( $type ), |
|
208 | + $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
209 | + ) |
|
210 | + ); |
|
211 | + } else { |
|
212 | + $invoice->add_system_note( |
|
213 | + sprintf( |
|
214 | + __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
215 | + sanitize_key( $type ), |
|
216 | + $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
217 | + ) |
|
218 | + ); |
|
219 | + } |
|
220 | + |
|
221 | + do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
272 | 222 | |
273 | - /** |
|
274 | - * Sends a subscription renewal reminder notification. |
|
275 | - * |
|
276 | - */ |
|
277 | - public function renewal_reminder() { |
|
223 | + } |
|
278 | 224 | |
279 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
225 | + /** |
|
226 | + * Sends a new trial notification. |
|
227 | + * |
|
228 | + * @param WPInv_Subscription $subscription |
|
229 | + */ |
|
230 | + public function subscription_trial( $subscription ) { |
|
280 | 231 | |
281 | - // Fetch reminder days. |
|
282 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
232 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
233 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
283 | 234 | |
284 | - // Abort if non is set. |
|
285 | - if ( empty( $reminder_days ) ) { |
|
286 | - return; |
|
287 | - } |
|
235 | + } |
|
288 | 236 | |
289 | - // Fetch matching subscriptions. |
|
237 | + /** |
|
238 | + * Sends a cancelled subscription notification. |
|
239 | + * |
|
240 | + * @param WPInv_Subscription $subscription |
|
241 | + */ |
|
242 | + public function subscription_cancelled( $subscription ) { |
|
243 | + |
|
244 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
245 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
246 | + |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * Sends a subscription expired notification. |
|
251 | + * |
|
252 | + * @param WPInv_Subscription $subscription |
|
253 | + */ |
|
254 | + public function subscription_expired( $subscription ) { |
|
255 | + |
|
256 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
257 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
258 | + |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * Sends a completed subscription notification. |
|
263 | + * |
|
264 | + * @param WPInv_Subscription $subscription |
|
265 | + */ |
|
266 | + public function subscription_complete( $subscription ) { |
|
267 | + |
|
268 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
269 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
270 | + |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * Sends a subscription renewal reminder notification. |
|
275 | + * |
|
276 | + */ |
|
277 | + public function renewal_reminder() { |
|
278 | + |
|
279 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
280 | + |
|
281 | + // Fetch reminder days. |
|
282 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
283 | + |
|
284 | + // Abort if non is set. |
|
285 | + if ( empty( $reminder_days ) ) { |
|
286 | + return; |
|
287 | + } |
|
288 | + |
|
289 | + // Fetch matching subscriptions. |
|
290 | 290 | $args = array( |
291 | 291 | 'number' => -1, |
292 | - 'count_total' => false, |
|
293 | - 'status' => 'trialling active', |
|
292 | + 'count_total' => false, |
|
293 | + 'status' => 'trialling active', |
|
294 | 294 | 'date_expires_query' => array( |
295 | - 'relation' => 'OR', |
|
295 | + 'relation' => 'OR', |
|
296 | 296 | ), |
297 | - ); |
|
297 | + ); |
|
298 | 298 | |
299 | - foreach ( $reminder_days as $days ) { |
|
300 | - $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
299 | + foreach ( $reminder_days as $days ) { |
|
300 | + $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
301 | 301 | |
302 | - $args['date_expires_query'][] = array( |
|
303 | - 'year' => $date['year'], |
|
304 | - 'month' => $date['month'], |
|
305 | - 'day' => $date['day'], |
|
306 | - ); |
|
302 | + $args['date_expires_query'][] = array( |
|
303 | + 'year' => $date['year'], |
|
304 | + 'month' => $date['month'], |
|
305 | + 'day' => $date['day'], |
|
306 | + ); |
|
307 | 307 | |
308 | - } |
|
308 | + } |
|
309 | 309 | |
310 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
310 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
311 | 311 | |
312 | 312 | foreach ( $subscriptions->get_results() as $subscription ) { |
313 | 313 | |
314 | - // Skip packages. |
|
315 | - if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) { |
|
316 | - $email->object = $subscription; |
|
317 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
318 | - } |
|
319 | - } |
|
314 | + // Skip packages. |
|
315 | + if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) { |
|
316 | + $email->object = $subscription; |
|
317 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
318 | + } |
|
319 | + } |
|
320 | 320 | |
321 | - } |
|
321 | + } |
|
322 | 322 | |
323 | 323 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * This class handles subscription notificaiton emails. |
@@ -45,21 +45,21 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function init_hooks() { |
47 | 47 | |
48 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
49 | - foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
48 | + add_filter('getpaid_get_email_merge_tags', array($this, 'subscription_merge_tags'), 10, 2); |
|
49 | + foreach ($this->subscription_actions as $hook => $email_type) { |
|
50 | 50 | |
51 | - $email = new GetPaid_Notification_Email( $email_type ); |
|
51 | + $email = new GetPaid_Notification_Email($email_type); |
|
52 | 52 | |
53 | - if ( ! $email->is_active() ) { |
|
53 | + if (!$email->is_active()) { |
|
54 | 54 | continue; |
55 | 55 | } |
56 | 56 | |
57 | - if ( method_exists( $this, $email_type ) ) { |
|
58 | - add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
57 | + if (method_exists($this, $email_type)) { |
|
58 | + add_action($hook, array($this, $email_type), 100, 2); |
|
59 | 59 | continue; |
60 | 60 | } |
61 | 61 | |
62 | - do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
62 | + do_action('getpaid_subscription_notification_email_register_hook', $email_type, $hook); |
|
63 | 63 | |
64 | 64 | } |
65 | 65 | |
@@ -71,12 +71,12 @@ discard block |
||
71 | 71 | * @param array $merge_tags |
72 | 72 | * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
73 | 73 | */ |
74 | - public function subscription_merge_tags( $merge_tags, $object ) { |
|
74 | + public function subscription_merge_tags($merge_tags, $object) { |
|
75 | 75 | |
76 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
76 | + if (is_a($object, 'WPInv_Subscription')) { |
|
77 | 77 | $merge_tags = array_merge( |
78 | 78 | $merge_tags, |
79 | - $this->get_subscription_merge_tags( $object ) |
|
79 | + $this->get_subscription_merge_tags($object) |
|
80 | 80 | ); |
81 | 81 | } |
82 | 82 | |
@@ -90,25 +90,25 @@ discard block |
||
90 | 90 | * @param WPInv_Subscription $subscription |
91 | 91 | * @return array |
92 | 92 | */ |
93 | - public function get_subscription_merge_tags( $subscription ) { |
|
93 | + public function get_subscription_merge_tags($subscription) { |
|
94 | 94 | |
95 | 95 | // Abort if it does not exist. |
96 | - if ( ! $subscription->get_id() ) { |
|
96 | + if (!$subscription->get_id()) { |
|
97 | 97 | return array(); |
98 | 98 | } |
99 | 99 | |
100 | - $invoice = $subscription->get_parent_invoice(); |
|
100 | + $invoice = $subscription->get_parent_invoice(); |
|
101 | 101 | return array( |
102 | - '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
103 | - '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
104 | - '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
105 | - '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
106 | - '{subscription_id}' => absint( $subscription->get_id() ), |
|
107 | - '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ), |
|
108 | - '{subscription_initial_amount}' => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ), |
|
109 | - '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
102 | + '{subscription_renewal_date}' => getpaid_format_date_value($subscription->get_next_renewal_date(), __('Never', 'invoicing')), |
|
103 | + '{subscription_created}' => getpaid_format_date_value($subscription->get_date_created()), |
|
104 | + '{subscription_status}' => sanitize_text_field($subscription->get_status_label()), |
|
105 | + '{subscription_profile_id}' => sanitize_text_field($subscription->get_profile_id()), |
|
106 | + '{subscription_id}' => absint($subscription->get_id()), |
|
107 | + '{subscription_recurring_amount}' => sanitize_text_field(wpinv_price($subscription->get_recurring_amount(), $invoice->get_currency())), |
|
108 | + '{subscription_initial_amount}' => sanitize_text_field(wpinv_price($subscription->get_initial_amount(), $invoice->get_currency())), |
|
109 | + '{subscription_recurring_period}' => getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), ''), |
|
110 | 110 | '{subscription_bill_times}' => $subscription->get_bill_times(), |
111 | - '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
111 | + '{subscription_url}' => esc_url($subscription->get_view_url()), |
|
112 | 112 | ); |
113 | 113 | |
114 | 114 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @param WPInv_Invoice $invoice |
120 | 120 | * @return bool |
121 | 121 | */ |
122 | - public function should_send_notification( $invoice ) { |
|
122 | + public function should_send_notification($invoice) { |
|
123 | 123 | return 0 != $invoice->get_id(); |
124 | 124 | } |
125 | 125 | |
@@ -129,14 +129,14 @@ discard block |
||
129 | 129 | * @param WPInv_Invoice $invoice |
130 | 130 | * @return array |
131 | 131 | */ |
132 | - public function get_recipients( $invoice ) { |
|
133 | - $recipients = array( $invoice->get_email() ); |
|
132 | + public function get_recipients($invoice) { |
|
133 | + $recipients = array($invoice->get_email()); |
|
134 | 134 | |
135 | 135 | $cc = $invoice->get_email_cc(); |
136 | 136 | |
137 | - if ( ! empty( $cc ) ) { |
|
138 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
139 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
137 | + if (!empty($cc)) { |
|
138 | + $cc = array_map('sanitize_email', wpinv_parse_list($cc)); |
|
139 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc))); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | return $recipients; |
@@ -150,75 +150,75 @@ discard block |
||
150 | 150 | * @param string $type |
151 | 151 | * @param array $extra_args Extra template args. |
152 | 152 | */ |
153 | - public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
153 | + public function send_email($subscription, $email, $type, $extra_args = array()) { |
|
154 | 154 | |
155 | - if ( empty( $subscription ) ) { |
|
155 | + if (empty($subscription)) { |
|
156 | 156 | return; |
157 | 157 | } |
158 | 158 | |
159 | - if ( is_array( $subscription ) ) { |
|
160 | - $subscription = current( $subscription ); |
|
159 | + if (is_array($subscription)) { |
|
160 | + $subscription = current($subscription); |
|
161 | 161 | } |
162 | 162 | |
163 | - if ( ! $subscription instanceof WPInv_Subscription ) { |
|
163 | + if (!$subscription instanceof WPInv_Subscription) { |
|
164 | 164 | return; |
165 | 165 | } |
166 | 166 | |
167 | 167 | // Abort in case the parent invoice does not exist. |
168 | 168 | $invoice = $subscription->get_parent_invoice(); |
169 | - if ( ! $this->should_send_notification( $invoice ) ) { |
|
169 | + if (!$this->should_send_notification($invoice)) { |
|
170 | 170 | return; |
171 | 171 | } |
172 | 172 | |
173 | - if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) { |
|
173 | + if (apply_filters('getpaid_skip_subscription_email', false, $type, $subscription)) { |
|
174 | 174 | return; |
175 | 175 | } |
176 | 176 | |
177 | - do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
177 | + do_action('getpaid_before_send_subscription_notification', $type, $subscription, $email); |
|
178 | 178 | |
179 | - $recipients = $this->get_recipients( $invoice ); |
|
179 | + $recipients = $this->get_recipients($invoice); |
|
180 | 180 | $mailer = new GetPaid_Notification_Email_Sender(); |
181 | 181 | $merge_tags = $email->get_merge_tags(); |
182 | - $content = $email->get_content( $merge_tags, $extra_args ); |
|
183 | - $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
182 | + $content = $email->get_content($merge_tags, $extra_args); |
|
183 | + $subject = $email->add_merge_tags($email->get_subject(), $merge_tags); |
|
184 | 184 | $attachments = $email->get_attachments(); |
185 | 185 | |
186 | 186 | $result = $mailer->send( |
187 | - apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
187 | + apply_filters('getpaid_subscription_email_recipients', wpinv_parse_list($recipients), $email), |
|
188 | 188 | $subject, |
189 | 189 | $content, |
190 | 190 | $attachments |
191 | 191 | ); |
192 | 192 | |
193 | 193 | // Maybe send a copy to the admin. |
194 | - if ( $email->include_admin_bcc() ) { |
|
194 | + if ($email->include_admin_bcc()) { |
|
195 | 195 | $mailer->send( |
196 | 196 | wpinv_get_admin_email(), |
197 | - $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
197 | + $subject . __(' - ADMIN BCC COPY', 'invoicing'), |
|
198 | 198 | $content, |
199 | 199 | $attachments |
200 | 200 | ); |
201 | 201 | } |
202 | 202 | |
203 | - if ( $result ) { |
|
203 | + if ($result) { |
|
204 | 204 | $invoice->add_system_note( |
205 | 205 | sprintf( |
206 | - __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
207 | - sanitize_key( $type ), |
|
208 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
206 | + __('Successfully sent %1$s notification email to %2$s.', 'invoicing'), |
|
207 | + sanitize_key($type), |
|
208 | + $email->is_admin_email() ? __('admin') : __('the customer') |
|
209 | 209 | ) |
210 | 210 | ); |
211 | 211 | } else { |
212 | 212 | $invoice->add_system_note( |
213 | 213 | sprintf( |
214 | - __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
215 | - sanitize_key( $type ), |
|
216 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
214 | + __('Failed sending %1$s notification email to %2$s.', 'invoicing'), |
|
215 | + sanitize_key($type), |
|
216 | + $email->is_admin_email() ? __('admin') : __('the customer') |
|
217 | 217 | ) |
218 | 218 | ); |
219 | 219 | } |
220 | 220 | |
221 | - do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
221 | + do_action('getpaid_after_send_subscription_notification', $type, $subscription, $email); |
|
222 | 222 | |
223 | 223 | } |
224 | 224 | |
@@ -227,10 +227,10 @@ discard block |
||
227 | 227 | * |
228 | 228 | * @param WPInv_Subscription $subscription |
229 | 229 | */ |
230 | - public function subscription_trial( $subscription ) { |
|
230 | + public function subscription_trial($subscription) { |
|
231 | 231 | |
232 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
233 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
232 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
233 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
234 | 234 | |
235 | 235 | } |
236 | 236 | |
@@ -239,10 +239,10 @@ discard block |
||
239 | 239 | * |
240 | 240 | * @param WPInv_Subscription $subscription |
241 | 241 | */ |
242 | - public function subscription_cancelled( $subscription ) { |
|
242 | + public function subscription_cancelled($subscription) { |
|
243 | 243 | |
244 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
245 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
244 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
245 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
246 | 246 | |
247 | 247 | } |
248 | 248 | |
@@ -251,10 +251,10 @@ discard block |
||
251 | 251 | * |
252 | 252 | * @param WPInv_Subscription $subscription |
253 | 253 | */ |
254 | - public function subscription_expired( $subscription ) { |
|
254 | + public function subscription_expired($subscription) { |
|
255 | 255 | |
256 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
257 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
256 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
257 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
258 | 258 | |
259 | 259 | } |
260 | 260 | |
@@ -263,10 +263,10 @@ discard block |
||
263 | 263 | * |
264 | 264 | * @param WPInv_Subscription $subscription |
265 | 265 | */ |
266 | - public function subscription_complete( $subscription ) { |
|
266 | + public function subscription_complete($subscription) { |
|
267 | 267 | |
268 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
269 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
268 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
269 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
270 | 270 | |
271 | 271 | } |
272 | 272 | |
@@ -276,18 +276,18 @@ discard block |
||
276 | 276 | */ |
277 | 277 | public function renewal_reminder() { |
278 | 278 | |
279 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
279 | + $email = new GetPaid_Notification_Email(__FUNCTION__); |
|
280 | 280 | |
281 | 281 | // Fetch reminder days. |
282 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
282 | + $reminder_days = array_unique(wp_parse_id_list($email->get_option('days'))); |
|
283 | 283 | |
284 | 284 | // Abort if non is set. |
285 | - if ( empty( $reminder_days ) ) { |
|
285 | + if (empty($reminder_days)) { |
|
286 | 286 | return; |
287 | 287 | } |
288 | 288 | |
289 | 289 | // Fetch matching subscriptions. |
290 | - $args = array( |
|
290 | + $args = array( |
|
291 | 291 | 'number' => -1, |
292 | 292 | 'count_total' => false, |
293 | 293 | 'status' => 'trialling active', |
@@ -296,8 +296,8 @@ discard block |
||
296 | 296 | ), |
297 | 297 | ); |
298 | 298 | |
299 | - foreach ( $reminder_days as $days ) { |
|
300 | - $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
299 | + foreach ($reminder_days as $days) { |
|
300 | + $date = date_parse(date('Y-m-d', strtotime("+$days days", current_time('timestamp')))); |
|
301 | 301 | |
302 | 302 | $args['date_expires_query'][] = array( |
303 | 303 | 'year' => $date['year'], |
@@ -307,14 +307,14 @@ discard block |
||
307 | 307 | |
308 | 308 | } |
309 | 309 | |
310 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
310 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
311 | 311 | |
312 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
312 | + foreach ($subscriptions->get_results() as $subscription) { |
|
313 | 313 | |
314 | 314 | // Skip packages. |
315 | - if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) { |
|
315 | + if (apply_filters('getpaid_send_subscription_renewal_reminder_email', true)) { |
|
316 | 316 | $email->object = $subscription; |
317 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
317 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
318 | 318 | } |
319 | 319 | } |
320 | 320 |
@@ -7,50 +7,50 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | -$class = ! is_singular( 'page' ) ? 'px-1' : ''; |
|
12 | +$class = !is_singular('page') ? 'px-1' : ''; |
|
13 | 13 | ?> |
14 | 14 | |
15 | - <?php do_action( 'getpaid_before_invoice_meta', $invoice ); ?> |
|
15 | + <?php do_action('getpaid_before_invoice_meta', $invoice); ?> |
|
16 | 16 | <div class="getpaid-invoice-meta-data"> |
17 | 17 | |
18 | - <?php do_action( 'getpaid_before_invoice_meta_table', $invoice ); ?> |
|
18 | + <?php do_action('getpaid_before_invoice_meta_table', $invoice); ?> |
|
19 | 19 | <table class="table table-bordered"> |
20 | 20 | <tbody> |
21 | 21 | |
22 | - <?php do_action( 'getpaid_before_invoice_meta_rows', $invoice ); ?> |
|
23 | - <?php foreach ( $meta as $key => $data ) : ?> |
|
22 | + <?php do_action('getpaid_before_invoice_meta_rows', $invoice); ?> |
|
23 | + <?php foreach ($meta as $key => $data) : ?> |
|
24 | 24 | |
25 | - <?php if ( ! empty( $data['value'] ) ) : ?> |
|
25 | + <?php if (!empty($data['value'])) : ?> |
|
26 | 26 | |
27 | - <?php do_action( "getpaid_before_invoice_meta_$key", $invoice, $data ); ?> |
|
27 | + <?php do_action("getpaid_before_invoice_meta_$key", $invoice, $data); ?> |
|
28 | 28 | |
29 | - <tr class="getpaid-invoice-meta-<?php echo esc_attr( $key ); ?>"> |
|
29 | + <tr class="getpaid-invoice-meta-<?php echo esc_attr($key); ?>"> |
|
30 | 30 | |
31 | - <th class="<?php echo esc_attr( $class ); ?> font-weight-bold" style="width: 40%"> |
|
32 | - <?php echo esc_html( $data['label'] ); ?> |
|
31 | + <th class="<?php echo esc_attr($class); ?> font-weight-bold" style="width: 40%"> |
|
32 | + <?php echo esc_html($data['label']); ?> |
|
33 | 33 | </th> |
34 | 34 | |
35 | - <td class="<?php echo esc_attr( $class ); ?> <?php echo 'invoice_total' === $key ? 'font-weight-bold' : 'font-weight-normal'; ?> text-break" style="width: 60%"> |
|
36 | - <span class="getpaid-invoice-meta-<?php echo esc_attr( $key ); ?>-value"><?php echo wp_kses_post( $data['value'] ); ?></span> |
|
35 | + <td class="<?php echo esc_attr($class); ?> <?php echo 'invoice_total' === $key ? 'font-weight-bold' : 'font-weight-normal'; ?> text-break" style="width: 60%"> |
|
36 | + <span class="getpaid-invoice-meta-<?php echo esc_attr($key); ?>-value"><?php echo wp_kses_post($data['value']); ?></span> |
|
37 | 37 | </td> |
38 | 38 | |
39 | 39 | </tr> |
40 | 40 | |
41 | - <?php do_action( "getpaid_after_invoice_meta_$key", $invoice, $data ); ?> |
|
41 | + <?php do_action("getpaid_after_invoice_meta_$key", $invoice, $data); ?> |
|
42 | 42 | |
43 | 43 | <?php endif; ?> |
44 | 44 | |
45 | 45 | <?php endforeach; ?> |
46 | - <?php do_action( 'getpaid_after_invoice_meta_rows', $invoice ); ?> |
|
46 | + <?php do_action('getpaid_after_invoice_meta_rows', $invoice); ?> |
|
47 | 47 | |
48 | 48 | </tbody> |
49 | 49 | </table> |
50 | - <?php do_action( 'getpaid_after_invoice_meta_table', $invoice ); ?> |
|
50 | + <?php do_action('getpaid_after_invoice_meta_table', $invoice); ?> |
|
51 | 51 | |
52 | 52 | |
53 | 53 | </div> |
54 | - <?php do_action( 'getpaid_after_invoice_meta', $invoice ); ?> |
|
54 | + <?php do_action('getpaid_after_invoice_meta', $invoice); ?> |
|
55 | 55 | |
56 | 56 | <?php |
@@ -39,40 +39,40 @@ |
||
39 | 39 | if ( 'tax' === $key ) { |
40 | 40 | wpinv_the_price( $invoice->get_total_tax(), $invoice->get_currency() ); |
41 | 41 | |
42 | - if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
42 | + if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
43 | 43 | |
44 | - $taxes = $invoice->get_total_tax(); |
|
45 | - if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) { |
|
46 | - echo ' <em class="text-muted small">'; |
|
47 | - _x( '(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing' ); |
|
48 | - echo '</em>'; |
|
44 | + $taxes = $invoice->get_total_tax(); |
|
45 | + if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) { |
|
46 | + echo ' <em class="text-muted small">'; |
|
47 | + _x( '(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing' ); |
|
48 | + echo '</em>'; |
|
49 | 49 | } |
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
53 | 53 | // Total Fee. |
54 | 54 | if ( 'fee' === $key ) { |
55 | - wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() ); |
|
55 | + wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() ); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | // Total discount. |
59 | 59 | if ( 'discount' === $key ) { |
60 | - wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); |
|
60 | + wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | // Shipping. |
64 | 64 | if ( 'shipping' === $key ) { |
65 | - wpinv_the_price( $invoice->get_shipping(), $invoice->get_currency() ); |
|
65 | + wpinv_the_price( $invoice->get_shipping(), $invoice->get_currency() ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | // Sub total. |
69 | 69 | if ( 'subtotal' === $key ) { |
70 | - wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); |
|
70 | + wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // Total. |
74 | 74 | if ( 'total' === $key ) { |
75 | - wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
75 | + wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // Fires when printing a cart total. |
@@ -9,26 +9,26 @@ discard block |
||
9 | 9 | * @var WPInv_Invoice $invoice |
10 | 10 | */ |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | // Totals rows. |
15 | -$totals = getpaid_invoice_totals_rows( $invoice ); |
|
15 | +$totals = getpaid_invoice_totals_rows($invoice); |
|
16 | 16 | |
17 | -do_action( 'getpaid_before_invoice_line_totals', $invoice, $totals ); |
|
17 | +do_action('getpaid_before_invoice_line_totals', $invoice, $totals); |
|
18 | 18 | |
19 | 19 | ?> |
20 | 20 | <div class='getpaid-invoice-line-totals'> |
21 | 21 | <div class="row"> |
22 | 22 | <div class="col-12 offset-sm-6 col-sm-6 border-sm-left pl-sm-0"> |
23 | 23 | |
24 | - <?php foreach ( $totals as $key => $label ) : ?> |
|
24 | + <?php foreach ($totals as $key => $label) : ?> |
|
25 | 25 | |
26 | - <div class="getpaid-invoice-line-totals-col <?php echo esc_attr( $key ); ?>"> |
|
26 | + <div class="getpaid-invoice-line-totals-col <?php echo esc_attr($key); ?>"> |
|
27 | 27 | |
28 | 28 | <div class="form-row row"> |
29 | 29 | |
30 | 30 | <div class="col-8 getpaid-invoice-line-totals-label"> |
31 | - <?php echo esc_html( $label ); ?> |
|
31 | + <?php echo esc_html($label); ?> |
|
32 | 32 | </div> |
33 | 33 | |
34 | 34 | <div class="col-4 getpaid-invoice-line-totals-value pl-0"> |
@@ -36,47 +36,47 @@ discard block |
||
36 | 36 | <?php |
37 | 37 | |
38 | 38 | // Total tax. |
39 | - if ( 'tax' === $key ) { |
|
40 | - wpinv_the_price( $invoice->get_total_tax(), $invoice->get_currency() ); |
|
39 | + if ('tax' === $key) { |
|
40 | + wpinv_the_price($invoice->get_total_tax(), $invoice->get_currency()); |
|
41 | 41 | |
42 | - if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
42 | + if (wpinv_use_taxes() && !$invoice->get_disable_taxes()) { |
|
43 | 43 | |
44 | 44 | $taxes = $invoice->get_total_tax(); |
45 | - if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) { |
|
45 | + if (empty($taxes) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction($invoice->get_country())) { |
|
46 | 46 | echo ' <em class="text-muted small">'; |
47 | - _x( '(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing' ); |
|
47 | + _x('(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing'); |
|
48 | 48 | echo '</em>'; |
49 | 49 | } |
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
53 | 53 | // Total Fee. |
54 | - if ( 'fee' === $key ) { |
|
55 | - wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() ); |
|
54 | + if ('fee' === $key) { |
|
55 | + wpinv_the_price($invoice->get_total_fees(), $invoice->get_currency()); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | // Total discount. |
59 | - if ( 'discount' === $key ) { |
|
60 | - wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); |
|
59 | + if ('discount' === $key) { |
|
60 | + wpinv_the_price($invoice->get_total_discount(), $invoice->get_currency()); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | // Shipping. |
64 | - if ( 'shipping' === $key ) { |
|
65 | - wpinv_the_price( $invoice->get_shipping(), $invoice->get_currency() ); |
|
64 | + if ('shipping' === $key) { |
|
65 | + wpinv_the_price($invoice->get_shipping(), $invoice->get_currency()); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | // Sub total. |
69 | - if ( 'subtotal' === $key ) { |
|
70 | - wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); |
|
69 | + if ('subtotal' === $key) { |
|
70 | + wpinv_the_price($invoice->get_subtotal(), $invoice->get_currency()); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // Total. |
74 | - if ( 'total' === $key ) { |
|
75 | - wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
74 | + if ('total' === $key) { |
|
75 | + wpinv_the_price($invoice->get_total(), $invoice->get_currency()); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // Fires when printing a cart total. |
79 | - do_action( "getpaid_invoice_cart_totals_$key", $invoice ); |
|
79 | + do_action("getpaid_invoice_cart_totals_$key", $invoice); |
|
80 | 80 | |
81 | 81 | ?> |
82 | 82 | |
@@ -90,4 +90,4 @@ discard block |
||
90 | 90 | </div> |
91 | 91 | </div> <!-- end .getpaid-invoice-line-totals --> |
92 | 92 | |
93 | -<?php do_action( 'getpaid_after_invoice_line_totals', $invoice, $totals ); ?> |
|
93 | +<?php do_action('getpaid_after_invoice_line_totals', $invoice, $totals); ?> |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | // Load WP_List_Table if not loaded |
13 | 13 | if ( ! class_exists( 'WP_List_Table' ) ) { |
14 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
14 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | /** |
@@ -23,375 +23,375 @@ discard block |
||
23 | 23 | */ |
24 | 24 | class WPInv_Customers_Table extends WP_List_Table { |
25 | 25 | |
26 | - /** |
|
27 | - * @var int Number of items per page |
|
28 | - * @since 1.0.19 |
|
29 | - */ |
|
30 | - public $per_page = 10; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var int Number of items |
|
34 | - * @since 1.0.19 |
|
35 | - */ |
|
36 | - public $total = 0; |
|
37 | - |
|
38 | - /** |
|
39 | - * Get things started |
|
40 | - * |
|
41 | - * @since 1.0.19 |
|
42 | - * @see WP_List_Table::__construct() |
|
43 | - */ |
|
44 | - public function __construct() { |
|
45 | - |
|
46 | - // Set parent defaults |
|
47 | - parent::__construct( |
|
26 | + /** |
|
27 | + * @var int Number of items per page |
|
28 | + * @since 1.0.19 |
|
29 | + */ |
|
30 | + public $per_page = 10; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var int Number of items |
|
34 | + * @since 1.0.19 |
|
35 | + */ |
|
36 | + public $total = 0; |
|
37 | + |
|
38 | + /** |
|
39 | + * Get things started |
|
40 | + * |
|
41 | + * @since 1.0.19 |
|
42 | + * @see WP_List_Table::__construct() |
|
43 | + */ |
|
44 | + public function __construct() { |
|
45 | + |
|
46 | + // Set parent defaults |
|
47 | + parent::__construct( |
|
48 | 48 | array( |
49 | - 'singular' => 'id', |
|
50 | - 'plural' => 'ids', |
|
51 | - 'ajax' => false, |
|
49 | + 'singular' => 'id', |
|
50 | + 'plural' => 'ids', |
|
51 | + 'ajax' => false, |
|
52 | 52 | ) |
53 | 53 | ); |
54 | 54 | |
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Gets the name of the primary column. |
|
59 | - * |
|
60 | - * @since 1.0.19 |
|
61 | - * @access protected |
|
62 | - * |
|
63 | - * @return string Name of the primary column. |
|
64 | - */ |
|
65 | - protected function get_primary_column_name() { |
|
66 | - return 'name'; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * This function renders most of the columns in the list table. |
|
71 | - * |
|
72 | - * @since 1.0.19 |
|
73 | - * |
|
74 | - * @param WP_User $item |
|
75 | - * @param string $column_name The name of the column |
|
76 | - * |
|
77 | - * @return string Column Name |
|
78 | - */ |
|
79 | - public function column_default( $item, $column_name ) { |
|
80 | - $value = esc_html( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) ); |
|
81 | - return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item ); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Displays the country column. |
|
86 | - * |
|
87 | - * @since 1.0.19 |
|
88 | - * |
|
89 | - * @param WP_User $user |
|
90 | - * |
|
91 | - * @return string Column Name |
|
92 | - */ |
|
93 | - public function column_country( $user ) { |
|
94 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
95 | - if ( $country ) { |
|
96 | - $country = wpinv_country_name( $country ); |
|
97 | - } |
|
98 | - return esc_html( $country ); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Displays the state column. |
|
103 | - * |
|
104 | - * @since 1.0.19 |
|
105 | - * |
|
106 | - * @param WP_User $user |
|
107 | - * |
|
108 | - * @return string Column Name |
|
109 | - */ |
|
110 | - public function column_state( $user ) { |
|
111 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
112 | - $state = $user->_wpinv_state; |
|
113 | - if ( $state ) { |
|
114 | - $state = wpinv_state_name( $state, $country ); |
|
115 | - } |
|
116 | - |
|
117 | - return esc_html( $state ); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Displays the signup column. |
|
122 | - * |
|
123 | - * @since 1.0.19 |
|
124 | - * |
|
125 | - * @param WP_User $user |
|
126 | - * |
|
127 | - * @return string Column Name |
|
128 | - */ |
|
129 | - public function column_signup( $user ) { |
|
130 | - return getpaid_format_date_value( $user->user_registered ); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Displays the total spent column. |
|
135 | - * |
|
136 | - * @since 1.0.19 |
|
137 | - * |
|
138 | - * @param WP_User $user |
|
139 | - * |
|
140 | - * @return string Column Name |
|
141 | - */ |
|
142 | - public function column_total( $user ) { |
|
143 | - return wpinv_price( $this->column_total_raw( $user ) ); |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Displays the total spent column. |
|
148 | - * |
|
149 | - * @since 1.0.19 |
|
150 | - * |
|
151 | - * @param WP_User $user |
|
152 | - * |
|
153 | - * @return float |
|
154 | - */ |
|
155 | - public function column_total_raw( $user ) { |
|
156 | - |
|
157 | - $args = array( |
|
158 | - 'data' => array( |
|
159 | - |
|
160 | - 'total' => array( |
|
161 | - 'type' => 'invoice_data', |
|
162 | - 'function' => 'SUM', |
|
163 | - 'name' => 'total_sales', |
|
164 | - ), |
|
165 | - |
|
166 | - ), |
|
167 | - 'where' => array( |
|
168 | - |
|
169 | - 'author' => array( |
|
170 | - 'type' => 'post_data', |
|
171 | - 'value' => absint( $user->ID ), |
|
172 | - 'key' => 'posts.post_author', |
|
173 | - 'operator' => '=', |
|
174 | - ), |
|
175 | - |
|
176 | - ), |
|
177 | - 'query_type' => 'get_var', |
|
178 | - 'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ), |
|
179 | - ); |
|
180 | - |
|
181 | - return wpinv_round_amount( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
182 | - |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Displays the total spent column. |
|
187 | - * |
|
188 | - * @since 1.0.19 |
|
189 | - * |
|
190 | - * @param WP_User $user |
|
191 | - * |
|
192 | - * @return string Column Name |
|
193 | - */ |
|
194 | - public function column_invoices( $user ) { |
|
195 | - |
|
196 | - $args = array( |
|
197 | - 'data' => array( |
|
198 | - |
|
199 | - 'ID' => array( |
|
200 | - 'type' => 'post_data', |
|
201 | - 'function' => 'COUNT', |
|
202 | - 'name' => 'count', |
|
203 | - 'distinct' => true, |
|
204 | - ), |
|
205 | - |
|
206 | - ), |
|
207 | - 'where' => array( |
|
208 | - |
|
209 | - 'author' => array( |
|
210 | - 'type' => 'post_data', |
|
211 | - 'value' => absint( $user->ID ), |
|
212 | - 'key' => 'posts.post_author', |
|
213 | - 'operator' => '=', |
|
214 | - ), |
|
215 | - |
|
216 | - ), |
|
217 | - 'query_type' => 'get_var', |
|
218 | - 'invoice_status' => array_keys( wpinv_get_invoice_statuses() ), |
|
219 | - ); |
|
220 | - |
|
221 | - $value = absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
222 | - $url = add_query_arg( array( 'post_type' => 'wpi_invoice', 'author' => $user->ID ), admin_url( 'edit.php' ) ); |
|
223 | - return empty( $value ) ? '0' : '<a href="' . esc_url( $url ) . '">' . absint( $value ) . '</a>'; |
|
224 | - |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * Generates content for a single row of the table |
|
229 | - * @since 1.0.19 |
|
230 | - * |
|
231 | - * @param int $item The user id. |
|
232 | - */ |
|
233 | - public function single_row( $item ) { |
|
234 | - $item = get_user_by( 'id', $item ); |
|
235 | - |
|
236 | - if ( empty( $item ) ) { |
|
237 | - return; |
|
238 | - } |
|
239 | - |
|
240 | - echo '<tr>'; |
|
241 | - $this->single_row_columns( $item ); |
|
242 | - echo '</tr>'; |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * Displays the customers name |
|
247 | - * |
|
248 | - * @param WP_User $customer customer. |
|
249 | - * @return string |
|
250 | - */ |
|
251 | - public function column_name( $customer ) { |
|
252 | - |
|
253 | - // Customer view URL. |
|
254 | - $view_url = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) ); |
|
255 | - $row_actions = $this->row_actions( |
|
256 | - array( |
|
257 | - 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>', |
|
258 | - ) |
|
259 | - ); |
|
260 | - |
|
261 | - // Get user's address. |
|
262 | - $address = wpinv_get_user_address( $customer->ID ); |
|
263 | - |
|
264 | - // Customer email address. |
|
265 | - $email = sanitize_email( $customer->user_email ); |
|
266 | - |
|
267 | - // Customer's avatar. |
|
268 | - $avatar = esc_url( get_avatar_url( $email ) ); |
|
269 | - $avatar = "<img src='$avatar' height='32' width='32'/>"; |
|
270 | - |
|
271 | - // Customer's name. |
|
272 | - $name = esc_html( "{$address['first_name']} {$address['last_name']}" ); |
|
273 | - |
|
274 | - if ( empty( trim( $name ) ) ) { |
|
275 | - $name = esc_html( $address['display_name'] ); |
|
276 | - } |
|
277 | - |
|
278 | - if ( ! empty( $name ) ) { |
|
279 | - $name = "<div style='overflow: hidden;height: 18px;'>$name</div>"; |
|
280 | - } |
|
281 | - |
|
282 | - $email = "<div class='row-title'><a href='$view_url'>$email</a></div>"; |
|
283 | - |
|
284 | - return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>"; |
|
285 | - |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * Retrieve the table columns |
|
290 | - * |
|
291 | - * @since 1.0.19 |
|
292 | - * @return array $columns Array of all the list table columns |
|
293 | - */ |
|
294 | - public function get_columns() { |
|
295 | - |
|
296 | - $columns = array( |
|
297 | - 'name' => __( 'Name', 'invoicing' ), |
|
298 | - 'country' => __( 'Country', 'invoicing' ), |
|
299 | - 'state' => __( 'State', 'invoicing' ), |
|
300 | - 'city' => __( 'City', 'invoicing' ), |
|
301 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
302 | - 'address' => __( 'Address', 'invoicing' ), |
|
303 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
304 | - 'company' => __( 'Company', 'invoicing' ), |
|
305 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
306 | - 'total' => __( 'Total Spend', 'invoicing' ), |
|
307 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
308 | - ); |
|
309 | - return apply_filters( 'wpinv_customers_table_columns', $columns ); |
|
310 | - |
|
311 | - } |
|
312 | - |
|
313 | - /** |
|
314 | - * Retrieve the current page number |
|
315 | - * |
|
316 | - * @since 1.0.19 |
|
317 | - * @return int Current page number |
|
318 | - */ |
|
319 | - public function get_paged() { |
|
320 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * Returns bulk actions. |
|
325 | - * |
|
326 | - * @since 1.0.19 |
|
327 | - * @return void |
|
328 | - */ |
|
329 | - public function bulk_actions( $which = '' ) { |
|
330 | - return array(); |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * Prepares the display query |
|
335 | - */ |
|
336 | - public function prepare_query() { |
|
337 | - global $wpdb; |
|
338 | - |
|
339 | - $post_types = ''; |
|
340 | - |
|
341 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
342 | - $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
343 | - } |
|
344 | - |
|
345 | - $post_types = rtrim( $post_types, ' OR' ); |
|
346 | - |
|
347 | - // Maybe search. |
|
348 | - if ( ! empty( $_POST['s'] ) ) { |
|
349 | - $users = get_users( |
|
350 | - array( |
|
351 | - 'search' => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*', |
|
352 | - 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
353 | - 'fields' => 'ID', |
|
354 | - ) |
|
355 | - ); |
|
356 | - |
|
357 | - $users = implode( ', ', $users ); |
|
358 | - $post_types = "($post_types) AND ( post_author IN ( $users ) )"; |
|
359 | - } |
|
360 | - |
|
361 | - // Users with invoices. |
|
362 | - $customers = $wpdb->get_col( |
|
363 | - $wpdb->prepare( |
|
364 | - "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d", |
|
365 | - $this->get_paged() * 10 - 10, |
|
366 | - $this->per_page |
|
367 | - ) |
|
368 | - ); |
|
369 | - |
|
370 | - $this->items = $customers; |
|
371 | - $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" ); |
|
372 | - |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * Setup the final data for the table |
|
377 | - * |
|
378 | - * @since 1.0.19 |
|
379 | - * @return void |
|
380 | - */ |
|
381 | - public function prepare_items() { |
|
382 | - $columns = $this->get_columns(); |
|
383 | - $hidden = array(); // No hidden columns |
|
384 | - $sortable = $this->get_sortable_columns(); |
|
385 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
386 | - $this->prepare_query(); |
|
387 | - |
|
388 | - $this->set_pagination_args( |
|
389 | - array( |
|
390 | - 'total_items' => $this->total, |
|
391 | - 'per_page' => $this->per_page, |
|
392 | - 'total_pages' => ceil( $this->total / $this->per_page ), |
|
393 | - ) |
|
394 | - ); |
|
395 | - |
|
396 | - } |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Gets the name of the primary column. |
|
59 | + * |
|
60 | + * @since 1.0.19 |
|
61 | + * @access protected |
|
62 | + * |
|
63 | + * @return string Name of the primary column. |
|
64 | + */ |
|
65 | + protected function get_primary_column_name() { |
|
66 | + return 'name'; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * This function renders most of the columns in the list table. |
|
71 | + * |
|
72 | + * @since 1.0.19 |
|
73 | + * |
|
74 | + * @param WP_User $item |
|
75 | + * @param string $column_name The name of the column |
|
76 | + * |
|
77 | + * @return string Column Name |
|
78 | + */ |
|
79 | + public function column_default( $item, $column_name ) { |
|
80 | + $value = esc_html( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) ); |
|
81 | + return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item ); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Displays the country column. |
|
86 | + * |
|
87 | + * @since 1.0.19 |
|
88 | + * |
|
89 | + * @param WP_User $user |
|
90 | + * |
|
91 | + * @return string Column Name |
|
92 | + */ |
|
93 | + public function column_country( $user ) { |
|
94 | + $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
95 | + if ( $country ) { |
|
96 | + $country = wpinv_country_name( $country ); |
|
97 | + } |
|
98 | + return esc_html( $country ); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Displays the state column. |
|
103 | + * |
|
104 | + * @since 1.0.19 |
|
105 | + * |
|
106 | + * @param WP_User $user |
|
107 | + * |
|
108 | + * @return string Column Name |
|
109 | + */ |
|
110 | + public function column_state( $user ) { |
|
111 | + $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
112 | + $state = $user->_wpinv_state; |
|
113 | + if ( $state ) { |
|
114 | + $state = wpinv_state_name( $state, $country ); |
|
115 | + } |
|
116 | + |
|
117 | + return esc_html( $state ); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Displays the signup column. |
|
122 | + * |
|
123 | + * @since 1.0.19 |
|
124 | + * |
|
125 | + * @param WP_User $user |
|
126 | + * |
|
127 | + * @return string Column Name |
|
128 | + */ |
|
129 | + public function column_signup( $user ) { |
|
130 | + return getpaid_format_date_value( $user->user_registered ); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Displays the total spent column. |
|
135 | + * |
|
136 | + * @since 1.0.19 |
|
137 | + * |
|
138 | + * @param WP_User $user |
|
139 | + * |
|
140 | + * @return string Column Name |
|
141 | + */ |
|
142 | + public function column_total( $user ) { |
|
143 | + return wpinv_price( $this->column_total_raw( $user ) ); |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Displays the total spent column. |
|
148 | + * |
|
149 | + * @since 1.0.19 |
|
150 | + * |
|
151 | + * @param WP_User $user |
|
152 | + * |
|
153 | + * @return float |
|
154 | + */ |
|
155 | + public function column_total_raw( $user ) { |
|
156 | + |
|
157 | + $args = array( |
|
158 | + 'data' => array( |
|
159 | + |
|
160 | + 'total' => array( |
|
161 | + 'type' => 'invoice_data', |
|
162 | + 'function' => 'SUM', |
|
163 | + 'name' => 'total_sales', |
|
164 | + ), |
|
165 | + |
|
166 | + ), |
|
167 | + 'where' => array( |
|
168 | + |
|
169 | + 'author' => array( |
|
170 | + 'type' => 'post_data', |
|
171 | + 'value' => absint( $user->ID ), |
|
172 | + 'key' => 'posts.post_author', |
|
173 | + 'operator' => '=', |
|
174 | + ), |
|
175 | + |
|
176 | + ), |
|
177 | + 'query_type' => 'get_var', |
|
178 | + 'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ), |
|
179 | + ); |
|
180 | + |
|
181 | + return wpinv_round_amount( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
182 | + |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Displays the total spent column. |
|
187 | + * |
|
188 | + * @since 1.0.19 |
|
189 | + * |
|
190 | + * @param WP_User $user |
|
191 | + * |
|
192 | + * @return string Column Name |
|
193 | + */ |
|
194 | + public function column_invoices( $user ) { |
|
195 | + |
|
196 | + $args = array( |
|
197 | + 'data' => array( |
|
198 | + |
|
199 | + 'ID' => array( |
|
200 | + 'type' => 'post_data', |
|
201 | + 'function' => 'COUNT', |
|
202 | + 'name' => 'count', |
|
203 | + 'distinct' => true, |
|
204 | + ), |
|
205 | + |
|
206 | + ), |
|
207 | + 'where' => array( |
|
208 | + |
|
209 | + 'author' => array( |
|
210 | + 'type' => 'post_data', |
|
211 | + 'value' => absint( $user->ID ), |
|
212 | + 'key' => 'posts.post_author', |
|
213 | + 'operator' => '=', |
|
214 | + ), |
|
215 | + |
|
216 | + ), |
|
217 | + 'query_type' => 'get_var', |
|
218 | + 'invoice_status' => array_keys( wpinv_get_invoice_statuses() ), |
|
219 | + ); |
|
220 | + |
|
221 | + $value = absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
222 | + $url = add_query_arg( array( 'post_type' => 'wpi_invoice', 'author' => $user->ID ), admin_url( 'edit.php' ) ); |
|
223 | + return empty( $value ) ? '0' : '<a href="' . esc_url( $url ) . '">' . absint( $value ) . '</a>'; |
|
224 | + |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * Generates content for a single row of the table |
|
229 | + * @since 1.0.19 |
|
230 | + * |
|
231 | + * @param int $item The user id. |
|
232 | + */ |
|
233 | + public function single_row( $item ) { |
|
234 | + $item = get_user_by( 'id', $item ); |
|
235 | + |
|
236 | + if ( empty( $item ) ) { |
|
237 | + return; |
|
238 | + } |
|
239 | + |
|
240 | + echo '<tr>'; |
|
241 | + $this->single_row_columns( $item ); |
|
242 | + echo '</tr>'; |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * Displays the customers name |
|
247 | + * |
|
248 | + * @param WP_User $customer customer. |
|
249 | + * @return string |
|
250 | + */ |
|
251 | + public function column_name( $customer ) { |
|
252 | + |
|
253 | + // Customer view URL. |
|
254 | + $view_url = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) ); |
|
255 | + $row_actions = $this->row_actions( |
|
256 | + array( |
|
257 | + 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>', |
|
258 | + ) |
|
259 | + ); |
|
260 | + |
|
261 | + // Get user's address. |
|
262 | + $address = wpinv_get_user_address( $customer->ID ); |
|
263 | + |
|
264 | + // Customer email address. |
|
265 | + $email = sanitize_email( $customer->user_email ); |
|
266 | + |
|
267 | + // Customer's avatar. |
|
268 | + $avatar = esc_url( get_avatar_url( $email ) ); |
|
269 | + $avatar = "<img src='$avatar' height='32' width='32'/>"; |
|
270 | + |
|
271 | + // Customer's name. |
|
272 | + $name = esc_html( "{$address['first_name']} {$address['last_name']}" ); |
|
273 | + |
|
274 | + if ( empty( trim( $name ) ) ) { |
|
275 | + $name = esc_html( $address['display_name'] ); |
|
276 | + } |
|
277 | + |
|
278 | + if ( ! empty( $name ) ) { |
|
279 | + $name = "<div style='overflow: hidden;height: 18px;'>$name</div>"; |
|
280 | + } |
|
281 | + |
|
282 | + $email = "<div class='row-title'><a href='$view_url'>$email</a></div>"; |
|
283 | + |
|
284 | + return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>"; |
|
285 | + |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * Retrieve the table columns |
|
290 | + * |
|
291 | + * @since 1.0.19 |
|
292 | + * @return array $columns Array of all the list table columns |
|
293 | + */ |
|
294 | + public function get_columns() { |
|
295 | + |
|
296 | + $columns = array( |
|
297 | + 'name' => __( 'Name', 'invoicing' ), |
|
298 | + 'country' => __( 'Country', 'invoicing' ), |
|
299 | + 'state' => __( 'State', 'invoicing' ), |
|
300 | + 'city' => __( 'City', 'invoicing' ), |
|
301 | + 'zip' => __( 'ZIP', 'invoicing' ), |
|
302 | + 'address' => __( 'Address', 'invoicing' ), |
|
303 | + 'phone' => __( 'Phone', 'invoicing' ), |
|
304 | + 'company' => __( 'Company', 'invoicing' ), |
|
305 | + 'invoices' => __( 'Invoices', 'invoicing' ), |
|
306 | + 'total' => __( 'Total Spend', 'invoicing' ), |
|
307 | + 'signup' => __( 'Date created', 'invoicing' ), |
|
308 | + ); |
|
309 | + return apply_filters( 'wpinv_customers_table_columns', $columns ); |
|
310 | + |
|
311 | + } |
|
312 | + |
|
313 | + /** |
|
314 | + * Retrieve the current page number |
|
315 | + * |
|
316 | + * @since 1.0.19 |
|
317 | + * @return int Current page number |
|
318 | + */ |
|
319 | + public function get_paged() { |
|
320 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * Returns bulk actions. |
|
325 | + * |
|
326 | + * @since 1.0.19 |
|
327 | + * @return void |
|
328 | + */ |
|
329 | + public function bulk_actions( $which = '' ) { |
|
330 | + return array(); |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * Prepares the display query |
|
335 | + */ |
|
336 | + public function prepare_query() { |
|
337 | + global $wpdb; |
|
338 | + |
|
339 | + $post_types = ''; |
|
340 | + |
|
341 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
342 | + $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
343 | + } |
|
344 | + |
|
345 | + $post_types = rtrim( $post_types, ' OR' ); |
|
346 | + |
|
347 | + // Maybe search. |
|
348 | + if ( ! empty( $_POST['s'] ) ) { |
|
349 | + $users = get_users( |
|
350 | + array( |
|
351 | + 'search' => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*', |
|
352 | + 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
353 | + 'fields' => 'ID', |
|
354 | + ) |
|
355 | + ); |
|
356 | + |
|
357 | + $users = implode( ', ', $users ); |
|
358 | + $post_types = "($post_types) AND ( post_author IN ( $users ) )"; |
|
359 | + } |
|
360 | + |
|
361 | + // Users with invoices. |
|
362 | + $customers = $wpdb->get_col( |
|
363 | + $wpdb->prepare( |
|
364 | + "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d", |
|
365 | + $this->get_paged() * 10 - 10, |
|
366 | + $this->per_page |
|
367 | + ) |
|
368 | + ); |
|
369 | + |
|
370 | + $this->items = $customers; |
|
371 | + $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" ); |
|
372 | + |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * Setup the final data for the table |
|
377 | + * |
|
378 | + * @since 1.0.19 |
|
379 | + * @return void |
|
380 | + */ |
|
381 | + public function prepare_items() { |
|
382 | + $columns = $this->get_columns(); |
|
383 | + $hidden = array(); // No hidden columns |
|
384 | + $sortable = $this->get_sortable_columns(); |
|
385 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
386 | + $this->prepare_query(); |
|
387 | + |
|
388 | + $this->set_pagination_args( |
|
389 | + array( |
|
390 | + 'total_items' => $this->total, |
|
391 | + 'per_page' => $this->per_page, |
|
392 | + 'total_pages' => ceil( $this->total / $this->per_page ), |
|
393 | + ) |
|
394 | + ); |
|
395 | + |
|
396 | + } |
|
397 | 397 | } |
@@ -5,12 +5,12 @@ discard block |
||
5 | 5 | */ |
6 | 6 | |
7 | 7 | // Exit if accessed directly |
8 | -if ( ! defined( 'ABSPATH' ) ) { |
|
8 | +if (!defined('ABSPATH')) { |
|
9 | 9 | exit; |
10 | 10 | } |
11 | 11 | |
12 | 12 | // Load WP_List_Table if not loaded |
13 | -if ( ! class_exists( 'WP_List_Table' ) ) { |
|
13 | +if (!class_exists('WP_List_Table')) { |
|
14 | 14 | require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
15 | 15 | } |
16 | 16 | |
@@ -76,9 +76,9 @@ discard block |
||
76 | 76 | * |
77 | 77 | * @return string Column Name |
78 | 78 | */ |
79 | - public function column_default( $item, $column_name ) { |
|
80 | - $value = esc_html( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) ); |
|
81 | - return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item ); |
|
79 | + public function column_default($item, $column_name) { |
|
80 | + $value = esc_html(get_user_meta($item->ID, '_wpinv_' . $column_name, true)); |
|
81 | + return apply_filters('wpinv_customers_table_column' . $column_name, $value, $item); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -90,12 +90,12 @@ discard block |
||
90 | 90 | * |
91 | 91 | * @return string Column Name |
92 | 92 | */ |
93 | - public function column_country( $user ) { |
|
94 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
95 | - if ( $country ) { |
|
96 | - $country = wpinv_country_name( $country ); |
|
93 | + public function column_country($user) { |
|
94 | + $country = wpinv_sanitize_country($user->_wpinv_country); |
|
95 | + if ($country) { |
|
96 | + $country = wpinv_country_name($country); |
|
97 | 97 | } |
98 | - return esc_html( $country ); |
|
98 | + return esc_html($country); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -107,14 +107,14 @@ discard block |
||
107 | 107 | * |
108 | 108 | * @return string Column Name |
109 | 109 | */ |
110 | - public function column_state( $user ) { |
|
111 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
110 | + public function column_state($user) { |
|
111 | + $country = wpinv_sanitize_country($user->_wpinv_country); |
|
112 | 112 | $state = $user->_wpinv_state; |
113 | - if ( $state ) { |
|
114 | - $state = wpinv_state_name( $state, $country ); |
|
113 | + if ($state) { |
|
114 | + $state = wpinv_state_name($state, $country); |
|
115 | 115 | } |
116 | 116 | |
117 | - return esc_html( $state ); |
|
117 | + return esc_html($state); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -126,8 +126,8 @@ discard block |
||
126 | 126 | * |
127 | 127 | * @return string Column Name |
128 | 128 | */ |
129 | - public function column_signup( $user ) { |
|
130 | - return getpaid_format_date_value( $user->user_registered ); |
|
129 | + public function column_signup($user) { |
|
130 | + return getpaid_format_date_value($user->user_registered); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | * |
140 | 140 | * @return string Column Name |
141 | 141 | */ |
142 | - public function column_total( $user ) { |
|
143 | - return wpinv_price( $this->column_total_raw( $user ) ); |
|
142 | + public function column_total($user) { |
|
143 | + return wpinv_price($this->column_total_raw($user)); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | * |
153 | 153 | * @return float |
154 | 154 | */ |
155 | - public function column_total_raw( $user ) { |
|
155 | + public function column_total_raw($user) { |
|
156 | 156 | |
157 | 157 | $args = array( |
158 | 158 | 'data' => array( |
@@ -168,17 +168,17 @@ discard block |
||
168 | 168 | |
169 | 169 | 'author' => array( |
170 | 170 | 'type' => 'post_data', |
171 | - 'value' => absint( $user->ID ), |
|
171 | + 'value' => absint($user->ID), |
|
172 | 172 | 'key' => 'posts.post_author', |
173 | 173 | 'operator' => '=', |
174 | 174 | ), |
175 | 175 | |
176 | 176 | ), |
177 | 177 | 'query_type' => 'get_var', |
178 | - 'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ), |
|
178 | + 'invoice_status' => array('wpi-renewal', 'wpi-processing', 'publish'), |
|
179 | 179 | ); |
180 | 180 | |
181 | - return wpinv_round_amount( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
181 | + return wpinv_round_amount(GetPaid_Reports_Helper::get_invoice_report_data($args)); |
|
182 | 182 | |
183 | 183 | } |
184 | 184 | |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | * |
192 | 192 | * @return string Column Name |
193 | 193 | */ |
194 | - public function column_invoices( $user ) { |
|
194 | + public function column_invoices($user) { |
|
195 | 195 | |
196 | 196 | $args = array( |
197 | 197 | 'data' => array( |
@@ -208,19 +208,19 @@ discard block |
||
208 | 208 | |
209 | 209 | 'author' => array( |
210 | 210 | 'type' => 'post_data', |
211 | - 'value' => absint( $user->ID ), |
|
211 | + 'value' => absint($user->ID), |
|
212 | 212 | 'key' => 'posts.post_author', |
213 | 213 | 'operator' => '=', |
214 | 214 | ), |
215 | 215 | |
216 | 216 | ), |
217 | 217 | 'query_type' => 'get_var', |
218 | - 'invoice_status' => array_keys( wpinv_get_invoice_statuses() ), |
|
218 | + 'invoice_status' => array_keys(wpinv_get_invoice_statuses()), |
|
219 | 219 | ); |
220 | 220 | |
221 | - $value = absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
222 | - $url = add_query_arg( array( 'post_type' => 'wpi_invoice', 'author' => $user->ID ), admin_url( 'edit.php' ) ); |
|
223 | - return empty( $value ) ? '0' : '<a href="' . esc_url( $url ) . '">' . absint( $value ) . '</a>'; |
|
221 | + $value = absint(GetPaid_Reports_Helper::get_invoice_report_data($args)); |
|
222 | + $url = add_query_arg(array('post_type' => 'wpi_invoice', 'author' => $user->ID), admin_url('edit.php')); |
|
223 | + return empty($value) ? '0' : '<a href="' . esc_url($url) . '">' . absint($value) . '</a>'; |
|
224 | 224 | |
225 | 225 | } |
226 | 226 | |
@@ -230,15 +230,15 @@ discard block |
||
230 | 230 | * |
231 | 231 | * @param int $item The user id. |
232 | 232 | */ |
233 | - public function single_row( $item ) { |
|
234 | - $item = get_user_by( 'id', $item ); |
|
233 | + public function single_row($item) { |
|
234 | + $item = get_user_by('id', $item); |
|
235 | 235 | |
236 | - if ( empty( $item ) ) { |
|
236 | + if (empty($item)) { |
|
237 | 237 | return; |
238 | 238 | } |
239 | 239 | |
240 | 240 | echo '<tr>'; |
241 | - $this->single_row_columns( $item ); |
|
241 | + $this->single_row_columns($item); |
|
242 | 242 | echo '</tr>'; |
243 | 243 | } |
244 | 244 | |
@@ -248,34 +248,34 @@ discard block |
||
248 | 248 | * @param WP_User $customer customer. |
249 | 249 | * @return string |
250 | 250 | */ |
251 | - public function column_name( $customer ) { |
|
251 | + public function column_name($customer) { |
|
252 | 252 | |
253 | 253 | // Customer view URL. |
254 | - $view_url = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) ); |
|
254 | + $view_url = esc_url(add_query_arg('user_id', $customer->ID, admin_url('user-edit.php'))); |
|
255 | 255 | $row_actions = $this->row_actions( |
256 | 256 | array( |
257 | - 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>', |
|
257 | + 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __('Edit Details', 'invoicing') . '</a>', |
|
258 | 258 | ) |
259 | 259 | ); |
260 | 260 | |
261 | 261 | // Get user's address. |
262 | - $address = wpinv_get_user_address( $customer->ID ); |
|
262 | + $address = wpinv_get_user_address($customer->ID); |
|
263 | 263 | |
264 | 264 | // Customer email address. |
265 | - $email = sanitize_email( $customer->user_email ); |
|
265 | + $email = sanitize_email($customer->user_email); |
|
266 | 266 | |
267 | 267 | // Customer's avatar. |
268 | - $avatar = esc_url( get_avatar_url( $email ) ); |
|
268 | + $avatar = esc_url(get_avatar_url($email)); |
|
269 | 269 | $avatar = "<img src='$avatar' height='32' width='32'/>"; |
270 | 270 | |
271 | 271 | // Customer's name. |
272 | - $name = esc_html( "{$address['first_name']} {$address['last_name']}" ); |
|
272 | + $name = esc_html("{$address['first_name']} {$address['last_name']}"); |
|
273 | 273 | |
274 | - if ( empty( trim( $name ) ) ) { |
|
275 | - $name = esc_html( $address['display_name'] ); |
|
274 | + if (empty(trim($name))) { |
|
275 | + $name = esc_html($address['display_name']); |
|
276 | 276 | } |
277 | 277 | |
278 | - if ( ! empty( $name ) ) { |
|
278 | + if (!empty($name)) { |
|
279 | 279 | $name = "<div style='overflow: hidden;height: 18px;'>$name</div>"; |
280 | 280 | } |
281 | 281 | |
@@ -294,19 +294,19 @@ discard block |
||
294 | 294 | public function get_columns() { |
295 | 295 | |
296 | 296 | $columns = array( |
297 | - 'name' => __( 'Name', 'invoicing' ), |
|
298 | - 'country' => __( 'Country', 'invoicing' ), |
|
299 | - 'state' => __( 'State', 'invoicing' ), |
|
300 | - 'city' => __( 'City', 'invoicing' ), |
|
301 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
302 | - 'address' => __( 'Address', 'invoicing' ), |
|
303 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
304 | - 'company' => __( 'Company', 'invoicing' ), |
|
305 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
306 | - 'total' => __( 'Total Spend', 'invoicing' ), |
|
307 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
297 | + 'name' => __('Name', 'invoicing'), |
|
298 | + 'country' => __('Country', 'invoicing'), |
|
299 | + 'state' => __('State', 'invoicing'), |
|
300 | + 'city' => __('City', 'invoicing'), |
|
301 | + 'zip' => __('ZIP', 'invoicing'), |
|
302 | + 'address' => __('Address', 'invoicing'), |
|
303 | + 'phone' => __('Phone', 'invoicing'), |
|
304 | + 'company' => __('Company', 'invoicing'), |
|
305 | + 'invoices' => __('Invoices', 'invoicing'), |
|
306 | + 'total' => __('Total Spend', 'invoicing'), |
|
307 | + 'signup' => __('Date created', 'invoicing'), |
|
308 | 308 | ); |
309 | - return apply_filters( 'wpinv_customers_table_columns', $columns ); |
|
309 | + return apply_filters('wpinv_customers_table_columns', $columns); |
|
310 | 310 | |
311 | 311 | } |
312 | 312 | |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | * @return int Current page number |
318 | 318 | */ |
319 | 319 | public function get_paged() { |
320 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
320 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | /** |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | * @since 1.0.19 |
327 | 327 | * @return void |
328 | 328 | */ |
329 | - public function bulk_actions( $which = '' ) { |
|
329 | + public function bulk_actions($which = '') { |
|
330 | 330 | return array(); |
331 | 331 | } |
332 | 332 | |
@@ -338,23 +338,23 @@ discard block |
||
338 | 338 | |
339 | 339 | $post_types = ''; |
340 | 340 | |
341 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
342 | - $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
341 | + foreach (array_keys(getpaid_get_invoice_post_types()) as $post_type) { |
|
342 | + $post_types .= $wpdb->prepare('post_type=%s OR ', $post_type); |
|
343 | 343 | } |
344 | 344 | |
345 | - $post_types = rtrim( $post_types, ' OR' ); |
|
345 | + $post_types = rtrim($post_types, ' OR'); |
|
346 | 346 | |
347 | 347 | // Maybe search. |
348 | - if ( ! empty( $_POST['s'] ) ) { |
|
348 | + if (!empty($_POST['s'])) { |
|
349 | 349 | $users = get_users( |
350 | 350 | array( |
351 | - 'search' => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*', |
|
352 | - 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
351 | + 'search' => '*' . sanitize_text_field(urldecode($_POST['s'])) . '*', |
|
352 | + 'search_columns' => array('user_login', 'user_email', 'display_name'), |
|
353 | 353 | 'fields' => 'ID', |
354 | 354 | ) |
355 | 355 | ); |
356 | 356 | |
357 | - $users = implode( ', ', $users ); |
|
357 | + $users = implode(', ', $users); |
|
358 | 358 | $post_types = "($post_types) AND ( post_author IN ( $users ) )"; |
359 | 359 | } |
360 | 360 | |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | ); |
369 | 369 | |
370 | 370 | $this->items = $customers; |
371 | - $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" ); |
|
371 | + $this->total = (int) $wpdb->get_var("SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types"); |
|
372 | 372 | |
373 | 373 | } |
374 | 374 | |
@@ -382,14 +382,14 @@ discard block |
||
382 | 382 | $columns = $this->get_columns(); |
383 | 383 | $hidden = array(); // No hidden columns |
384 | 384 | $sortable = $this->get_sortable_columns(); |
385 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
385 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
386 | 386 | $this->prepare_query(); |
387 | 387 | |
388 | 388 | $this->set_pagination_args( |
389 | 389 | array( |
390 | 390 | 'total_items' => $this->total, |
391 | 391 | 'per_page' => $this->per_page, |
392 | - 'total_pages' => ceil( $this->total / $this->per_page ), |
|
392 | + 'total_pages' => ceil($this->total / $this->per_page), |
|
393 | 393 | ) |
394 | 394 | ); |
395 | 395 |
@@ -7,20 +7,20 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | -$class = empty( $class ) ? 'btn-primary' : sanitize_html_class( $class ); |
|
13 | -$label = empty( $label ) ? esc_attr__( 'Pay %price% »', 'invoicing' ) : esc_attr( $label ); |
|
14 | -$free = empty( $free ) ? esc_attr__( 'Continue »', 'invoicing' ) : esc_attr( $free ); |
|
12 | +$class = empty($class) ? 'btn-primary' : sanitize_html_class($class); |
|
13 | +$label = empty($label) ? esc_attr__('Pay %price% »', 'invoicing') : esc_attr($label); |
|
14 | +$free = empty($free) ? esc_attr__('Continue »', 'invoicing') : esc_attr($free); |
|
15 | 15 | |
16 | -do_action( 'getpaid_before_payment_form_pay_button', $form ); |
|
16 | +do_action('getpaid_before_payment_form_pay_button', $form); |
|
17 | 17 | |
18 | 18 | aui()->input( |
19 | 19 | array( |
20 | - 'name' => esc_attr( $id ), |
|
21 | - 'id' => esc_attr( $element_id ), |
|
20 | + 'name' => esc_attr($id), |
|
21 | + 'id' => esc_attr($element_id), |
|
22 | 22 | 'value' => $label, |
23 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
23 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
24 | 24 | 'type' => 'submit', |
25 | 25 | 'class' => 'getpaid-payment-form-submit btn btn-block submit-button ' . $class, |
26 | 26 | 'extra_attributes' => array( |
@@ -31,4 +31,4 @@ discard block |
||
31 | 31 | true |
32 | 32 | ); |
33 | 33 | |
34 | -do_action( 'getpaid_after_payment_form_pay_button', $form ); |
|
34 | +do_action('getpaid_after_payment_form_pay_button', $form); |
@@ -7,24 +7,24 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | -$label = empty( $label ) ? '' : wp_kses_post( $label ); |
|
13 | -$label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) ); |
|
12 | +$label = empty($label) ? '' : wp_kses_post($label); |
|
13 | +$label_class = sanitize_key(preg_replace('/[^A-Za-z0-9_-]/', '-', $label)); |
|
14 | 14 | |
15 | -if ( ! empty( $required ) ) { |
|
15 | +if (!empty($required)) { |
|
16 | 16 | $label .= "<span class='text-danger'> *</span>"; |
17 | 17 | } |
18 | 18 | |
19 | 19 | aui()->input( |
20 | 20 | array( |
21 | 21 | 'type' => 'checkbox', |
22 | - 'name' => esc_attr( $id ), |
|
23 | - 'id' => esc_attr( $element_id ), |
|
24 | - 'required' => ! empty( $required ), |
|
22 | + 'name' => esc_attr($id), |
|
23 | + 'id' => esc_attr($element_id), |
|
24 | + 'required' => !empty($required), |
|
25 | 25 | 'label' => $label, |
26 | - 'value' => esc_attr__( 'Yes', 'invoicing' ), |
|
27 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
26 | + 'value' => esc_attr__('Yes', 'invoicing'), |
|
27 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
28 | 28 | 'class' => 'w-auto ' . $label_class, |
29 | 29 | ), |
30 | 30 | true |