@@ -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 function is responsible for sending emails. |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @return bool |
34 | 34 | */ |
35 | - public function send( $to, $subject, $email, $attachments = array() ) { |
|
35 | + public function send($to, $subject, $email, $attachments = array()) { |
|
36 | 36 | |
37 | 37 | /* |
38 | 38 | * Allow to filter data on per-email basis. |
@@ -40,9 +40,9 @@ discard block |
||
40 | 40 | $data = apply_filters( |
41 | 41 | 'getpaid_email_data', |
42 | 42 | array( |
43 | - 'to' => array_filter( array_unique( wpinv_parse_list( $to ) ) ), |
|
44 | - 'subject' => htmlspecialchars_decode( strip_tags( $subject ), ENT_QUOTES ), |
|
45 | - 'email' => apply_filters( 'wpinv_mail_content', $email ), |
|
43 | + 'to' => array_filter(array_unique(wpinv_parse_list($to))), |
|
44 | + 'subject' => htmlspecialchars_decode(strip_tags($subject), ENT_QUOTES), |
|
45 | + 'email' => apply_filters('wpinv_mail_content', $email), |
|
46 | 46 | 'headers' => $this->get_headers(), |
47 | 47 | 'attachments' => $attachments, |
48 | 48 | ), |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | ); |
51 | 51 | |
52 | 52 | // Remove slashes. |
53 | - $data = (array) wp_unslash( $data ); |
|
53 | + $data = (array) wp_unslash($data); |
|
54 | 54 | |
55 | 55 | // Cache it. |
56 | 56 | $this->wp_mail_data = $data; |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | |
61 | 61 | $result = false; |
62 | 62 | |
63 | - foreach ( $this->wp_mail_data['to'] as $to ) { |
|
64 | - $result = $this->_send( $to, $data ); |
|
63 | + foreach ($this->wp_mail_data['to'] as $to) { |
|
64 | + $result = $this->_send($to, $data); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | // Remove our hooks. |
@@ -82,24 +82,24 @@ discard block |
||
82 | 82 | * |
83 | 83 | * @return bool |
84 | 84 | */ |
85 | - protected function _send( $to, $data ) { |
|
85 | + protected function _send($to, $data) { |
|
86 | 86 | |
87 | 87 | // Prepare the sending function. |
88 | - $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' ); |
|
88 | + $sending_function = apply_filters('getpaid_email_email_sending_function', 'wp_mail'); |
|
89 | 89 | |
90 | 90 | // Send the actual email. |
91 | 91 | $result = call_user_func( |
92 | 92 | $sending_function, |
93 | 93 | $to, |
94 | - html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ), |
|
94 | + html_entity_decode($data['subject'], ENT_QUOTES, get_bloginfo('charset')), |
|
95 | 95 | $data['email'], |
96 | 96 | $data['headers'], |
97 | 97 | $data['attachments'] |
98 | 98 | ); |
99 | 99 | |
100 | - if ( ! $result ) { |
|
101 | - $log_message = wp_sprintf( __( "\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] ); |
|
102 | - wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ ); |
|
100 | + if (!$result) { |
|
101 | + $log_message = wp_sprintf(__("\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing'), date_i18n('F j Y H:i:s', current_time('timestamp')), $to, $data['subject']); |
|
102 | + wpinv_error_log($log_message, __('Email from Invoicing plugin failed to send', 'invoicing'), __FILE__, __LINE__); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | return $result; |
@@ -112,9 +112,9 @@ discard block |
||
112 | 112 | |
113 | 113 | $name = $this->get_from_name(); |
114 | 114 | $reply_to = $this->get_reply_to(); |
115 | - $headers = array( "Reply-To:$name <$reply_to>" ); |
|
115 | + $headers = array("Reply-To:$name <$reply_to>"); |
|
116 | 116 | |
117 | - return apply_filters( 'getpaid_email_headers', $headers, $this ); |
|
117 | + return apply_filters('getpaid_email_headers', $headers, $this); |
|
118 | 118 | |
119 | 119 | } |
120 | 120 | |
@@ -125,11 +125,11 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function before_sending() { |
127 | 127 | |
128 | - do_action( 'getpaid_before_send_email', $this ); |
|
129 | - add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
130 | - add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
131 | - add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
132 | - add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
128 | + do_action('getpaid_before_send_email', $this); |
|
129 | + add_filter('wp_mail_from', array($this, 'get_from_address'), 1000); |
|
130 | + add_filter('wp_mail_from_name', array($this, 'get_from_name'), 1000); |
|
131 | + add_filter('wp_mail_content_type', array($this, 'get_content_type'), 1000); |
|
132 | + add_filter('wp_mail', array($this, 'ensure_email_content'), 1000); |
|
133 | 133 | |
134 | 134 | } |
135 | 135 | |
@@ -138,13 +138,13 @@ discard block |
||
138 | 138 | */ |
139 | 139 | public function get_from_name() { |
140 | 140 | |
141 | - $from_name = wpinv_get_option( 'email_from_name', get_bloginfo( 'name' ) ); |
|
141 | + $from_name = wpinv_get_option('email_from_name', get_bloginfo('name')); |
|
142 | 142 | |
143 | - if ( empty( $from_name ) ) { |
|
144 | - $from_name = get_bloginfo( 'name' ); |
|
143 | + if (empty($from_name)) { |
|
144 | + $from_name = get_bloginfo('name'); |
|
145 | 145 | } |
146 | 146 | |
147 | - return wp_specialchars_decode( $from_name, ENT_QUOTES ); |
|
147 | + return wp_specialchars_decode($from_name, ENT_QUOTES); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -152,9 +152,9 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function get_from_address() { |
154 | 154 | |
155 | - $from_address = wpinv_get_option( 'email_from', $this->default_from_address() ); |
|
155 | + $from_address = wpinv_get_option('email_from', $this->default_from_address()); |
|
156 | 156 | |
157 | - if ( ! is_email( $from_address ) ) { |
|
157 | + if (!is_email($from_address)) { |
|
158 | 158 | $from_address = $this->default_from_address(); |
159 | 159 | } |
160 | 160 | |
@@ -174,14 +174,14 @@ discard block |
||
174 | 174 | public function default_from_address() { |
175 | 175 | |
176 | 176 | // Get the site domain and get rid of www. |
177 | - $sitename = strtolower( $_SERVER['SERVER_NAME'] ); |
|
178 | - if ( substr( $sitename, 0, 4 ) == 'www.' ) { |
|
179 | - $sitename = substr( $sitename, 4 ); |
|
177 | + $sitename = strtolower($_SERVER['SERVER_NAME']); |
|
178 | + if (substr($sitename, 0, 4) == 'www.') { |
|
179 | + $sitename = substr($sitename, 4); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | $from_email = 'wordpress@' . $sitename; |
183 | 183 | |
184 | - return apply_filters( 'getpaid_default_from_address', $from_email ); |
|
184 | + return apply_filters('getpaid_default_from_address', $from_email); |
|
185 | 185 | |
186 | 186 | } |
187 | 187 | |
@@ -195,8 +195,8 @@ discard block |
||
195 | 195 | |
196 | 196 | $reply_to = wpinv_get_admin_email(); |
197 | 197 | |
198 | - if ( ! is_email( $reply_to ) ) { |
|
199 | - $reply_to = get_option( 'admin_email' ); |
|
198 | + if (!is_email($reply_to)) { |
|
199 | + $reply_to = get_option('admin_email'); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | return $reply_to; |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | * |
208 | 208 | */ |
209 | 209 | public function get_content_type() { |
210 | - return apply_filters( 'getpaid_email_content_type', 'text/html', $this ); |
|
210 | + return apply_filters('getpaid_email_content_type', 'text/html', $this); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @return array wp_mail_data. |
217 | 217 | */ |
218 | - public function ensure_email_content( $args ) { |
|
218 | + public function ensure_email_content($args) { |
|
219 | 219 | $args['message'] = $this->wp_mail_data['email']; |
220 | 220 | return $args; |
221 | 221 | } |
@@ -226,11 +226,11 @@ discard block |
||
226 | 226 | */ |
227 | 227 | public function after_sending() { |
228 | 228 | |
229 | - do_action( 'getpaid_after_send_email', $this->wp_mail_data ); |
|
230 | - remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
231 | - remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
232 | - remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
233 | - remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
229 | + do_action('getpaid_after_send_email', $this->wp_mail_data); |
|
230 | + remove_filter('wp_mail_from', array($this, 'get_from_address'), 1000); |
|
231 | + remove_filter('wp_mail_from_name', array($this, 'get_from_name'), 1000); |
|
232 | + remove_filter('wp_mail_content_type', array($this, 'get_content_type'), 1000); |
|
233 | + remove_filter('wp_mail', array($this, 'ensure_email_content'), 1000); |
|
234 | 234 | |
235 | 235 | } |
236 | 236 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 1.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Main Invoicing class. |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | * @param string $prop The prop to set. |
57 | 57 | * @param mixed $value The value to retrieve. |
58 | 58 | */ |
59 | - public function set( $prop, $value ) { |
|
60 | - $this->data[ $prop ] = $value; |
|
59 | + public function set($prop, $value) { |
|
60 | + $this->data[$prop] = $value; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | * @param string $prop The prop to set. |
67 | 67 | * @return mixed The value. |
68 | 68 | */ |
69 | - public function get( $prop ) { |
|
69 | + public function get($prop) { |
|
70 | 70 | |
71 | - if ( isset( $this->data[ $prop ] ) ) { |
|
72 | - return $this->data[ $prop ]; |
|
71 | + if (isset($this->data[$prop])) { |
|
72 | + return $this->data[$prop]; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | return null; |
@@ -81,23 +81,23 @@ discard block |
||
81 | 81 | public function set_properties() { |
82 | 82 | |
83 | 83 | // Sessions. |
84 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
84 | + $this->set('session', new WPInv_Session_Handler()); |
|
85 | + $GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility. |
|
86 | 86 | $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
87 | 87 | |
88 | 88 | // Init other objects. |
89 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
90 | - $this->set( 'notes', new WPInv_Notes() ); |
|
91 | - $this->set( 'api', new WPInv_API() ); |
|
92 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | - $this->set( 'template', new GetPaid_Template() ); |
|
94 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
89 | + $this->set('session', new WPInv_Session_Handler()); |
|
90 | + $this->set('notes', new WPInv_Notes()); |
|
91 | + $this->set('api', new WPInv_API()); |
|
92 | + $this->set('post_types', new GetPaid_Post_Types()); |
|
93 | + $this->set('template', new GetPaid_Template()); |
|
94 | + $this->set('admin', new GetPaid_Admin()); |
|
95 | + $this->set('subscriptions', new WPInv_Subscriptions()); |
|
96 | + $this->set('invoice_emails', new GetPaid_Invoice_Notification_Emails()); |
|
97 | + $this->set('subscription_emails', new GetPaid_Subscription_Notification_Emails()); |
|
98 | + $this->set('daily_maintenace', new GetPaid_Daily_Maintenance()); |
|
99 | + $this->set('payment_forms', new GetPaid_Payment_Forms()); |
|
100 | + $this->set('maxmind', new GetPaid_MaxMind_Geolocation()); |
|
101 | 101 | |
102 | 102 | } |
103 | 103 | |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | * Define plugin constants. |
106 | 106 | */ |
107 | 107 | public function define_constants() { |
108 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
108 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
109 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
110 | 110 | $this->version = WPINV_VERSION; |
111 | 111 | } |
112 | 112 | |
@@ -117,27 +117,27 @@ discard block |
||
117 | 117 | */ |
118 | 118 | protected function init_hooks() { |
119 | 119 | /* Internationalize the text strings used. */ |
120 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
120 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
121 | 121 | |
122 | 122 | // Init the plugin after WordPress inits. |
123 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
127 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
128 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
129 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
130 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
131 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
132 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
133 | - |
|
134 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
135 | - add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
|
136 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
123 | + add_action('init', array($this, 'init'), 1); |
|
124 | + add_action('init', array($this, 'maybe_process_ipn'), 10); |
|
125 | + add_action('init', array($this, 'wpinv_actions')); |
|
126 | + add_action('init', array($this, 'maybe_do_authenticated_action'), 100); |
|
127 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 11); |
|
128 | + add_action('wp_footer', array($this, 'wp_footer')); |
|
129 | + add_action('wp_head', array($this, 'wp_head')); |
|
130 | + add_action('widgets_init', array($this, 'register_widgets')); |
|
131 | + add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids')); |
|
132 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
133 | + |
|
134 | + add_filter('query_vars', array($this, 'custom_query_vars')); |
|
135 | + add_action('init', array($this, 'add_rewrite_rule'), 10, 0); |
|
136 | + add_action('pre_get_posts', array($this, 'maybe_process_new_ipn'), 1); |
|
137 | 137 | |
138 | 138 | // Fires after registering actions. |
139 | - do_action( 'wpinv_actions', $this ); |
|
140 | - do_action( 'getpaid_actions', $this ); |
|
139 | + do_action('wpinv_actions', $this); |
|
140 | + do_action('getpaid_actions', $this); |
|
141 | 141 | |
142 | 142 | } |
143 | 143 | |
@@ -145,10 +145,10 @@ discard block |
||
145 | 145 | /* Internationalize the text strings used. */ |
146 | 146 | $this->load_textdomain(); |
147 | 147 | |
148 | - do_action( 'wpinv_loaded' ); |
|
148 | + do_action('wpinv_loaded'); |
|
149 | 149 | |
150 | 150 | // Fix oxygen page builder conflict |
151 | - if ( function_exists( 'ct_css_output' ) ) { |
|
151 | + if (function_exists('ct_css_output')) { |
|
152 | 152 | wpinv_oxygen_fix_conflict(); |
153 | 153 | } |
154 | 154 | } |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | load_plugin_textdomain( |
170 | 170 | 'invoicing', |
171 | 171 | false, |
172 | - plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' |
|
172 | + plugin_basename(dirname(WPINV_PLUGIN_FILE)) . '/languages/' |
|
173 | 173 | ); |
174 | 174 | |
175 | 175 | } |
@@ -205,9 +205,9 @@ discard block |
||
205 | 205 | |
206 | 206 | // Register autoloader. |
207 | 207 | try { |
208 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
209 | - } catch ( Exception $e ) { |
|
210 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
208 | + spl_autoload_register(array($this, 'autoload'), true); |
|
209 | + } catch (Exception $e) { |
|
210 | + wpinv_error_log($e->getMessage(), '', __FILE__, 149, true); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
234 | 234 | require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
235 | 235 | |
236 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
236 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
237 | 237 | GetPaid_Post_Types_Admin::init(); |
238 | 238 | |
239 | 239 | require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
@@ -244,15 +244,15 @@ discard block |
||
244 | 244 | require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
245 | 245 | // load the user class only on the users.php page |
246 | 246 | global $pagenow; |
247 | - if ( $pagenow == 'users.php' ) { |
|
247 | + if ($pagenow == 'users.php') { |
|
248 | 248 | new WPInv_Admin_Users(); |
249 | 249 | } |
250 | 250 | } |
251 | 251 | |
252 | 252 | // Register cli commands |
253 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
253 | + if (defined('WP_CLI') && WP_CLI) { |
|
254 | 254 | require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
255 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
255 | + WP_CLI::add_command('invoicing', 'WPInv_CLI'); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | } |
@@ -265,21 +265,21 @@ discard block |
||
265 | 265 | * @since 1.0.19 |
266 | 266 | * @return void |
267 | 267 | */ |
268 | - public function autoload( $class_name ) { |
|
268 | + public function autoload($class_name) { |
|
269 | 269 | |
270 | 270 | // Normalize the class name... |
271 | - $class_name = strtolower( $class_name ); |
|
271 | + $class_name = strtolower($class_name); |
|
272 | 272 | |
273 | 273 | // ... and make sure it is our class. |
274 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
274 | + if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) { |
|
275 | 275 | return; |
276 | 276 | } |
277 | 277 | |
278 | 278 | // Next, prepare the file name from the class. |
279 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
279 | + $file_name = 'class-' . str_replace('_', '-', $class_name) . '.php'; |
|
280 | 280 | |
281 | 281 | // Base path of the classes. |
282 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
282 | + $plugin_path = untrailingslashit(WPINV_PLUGIN_DIR); |
|
283 | 283 | |
284 | 284 | // And an array of possible locations in order of importance. |
285 | 285 | $locations = array( |
@@ -294,10 +294,10 @@ discard block |
||
294 | 294 | "$plugin_path/includes/admin/meta-boxes", |
295 | 295 | ); |
296 | 296 | |
297 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
297 | + foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) { |
|
298 | 298 | |
299 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
300 | - include trailingslashit( $location ) . $file_name; |
|
299 | + if (file_exists(trailingslashit($location) . $file_name)) { |
|
300 | + include trailingslashit($location) . $file_name; |
|
301 | 301 | break; |
302 | 302 | } |
303 | 303 | } |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | public function init() { |
311 | 311 | |
312 | 312 | // Fires before getpaid inits. |
313 | - do_action( 'before_getpaid_init', $this ); |
|
313 | + do_action('before_getpaid_init', $this); |
|
314 | 314 | |
315 | 315 | // Maybe upgrade. |
316 | 316 | $this->maybe_upgrade_database(); |
@@ -327,17 +327,17 @@ discard block |
||
327 | 327 | ) |
328 | 328 | ); |
329 | 329 | |
330 | - foreach ( $gateways as $id => $class ) { |
|
331 | - $this->gateways[ $id ] = new $class(); |
|
330 | + foreach ($gateways as $id => $class) { |
|
331 | + $this->gateways[$id] = new $class(); |
|
332 | 332 | } |
333 | 333 | |
334 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
334 | + if ('yes' != get_option('wpinv_renamed_gateways')) { |
|
335 | 335 | GetPaid_Installer::rename_gateways_label(); |
336 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
336 | + update_option('wpinv_renamed_gateways', 'yes'); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | // Fires after getpaid inits. |
340 | - do_action( 'getpaid_init', $this ); |
|
340 | + do_action('getpaid_init', $this); |
|
341 | 341 | |
342 | 342 | } |
343 | 343 | |
@@ -347,14 +347,14 @@ discard block |
||
347 | 347 | public function maybe_process_ipn() { |
348 | 348 | |
349 | 349 | // Ensure that this is an IPN request. |
350 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
350 | + if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) { |
|
351 | 351 | return; |
352 | 352 | } |
353 | 353 | |
354 | - $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
354 | + $gateway = sanitize_text_field($_GET['wpi-gateway']); |
|
355 | 355 | |
356 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
357 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
356 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
357 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
358 | 358 | exit; |
359 | 359 | |
360 | 360 | } |
@@ -362,33 +362,33 @@ discard block |
||
362 | 362 | public function enqueue_scripts() { |
363 | 363 | |
364 | 364 | // Fires before adding scripts. |
365 | - do_action( 'getpaid_enqueue_scripts' ); |
|
365 | + do_action('getpaid_enqueue_scripts'); |
|
366 | 366 | |
367 | 367 | $localize = array(); |
368 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
368 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
369 | 369 | $localize['thousands'] = wpinv_thousands_separator(); |
370 | 370 | $localize['decimals'] = wpinv_decimal_separator(); |
371 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
372 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
371 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
372 | + $localize['txtComplete'] = __('Continue', 'invoicing'); |
|
373 | 373 | $localize['UseTaxes'] = wpinv_use_taxes(); |
374 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
375 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
376 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
374 | + $localize['formNonce'] = wp_create_nonce('getpaid_form_nonce'); |
|
375 | + $localize['loading'] = __('Loading...', 'invoicing'); |
|
376 | + $localize['connectionError'] = __('Could not establish a connection to the server.', 'invoicing'); |
|
377 | 377 | |
378 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
378 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
379 | 379 | |
380 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
381 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
382 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
380 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js'); |
|
381 | + wp_enqueue_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('jquery'), $version, true); |
|
382 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | public function wpinv_actions() { |
386 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
387 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
386 | + if (isset($_REQUEST['wpi_action'])) { |
|
387 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
388 | 388 | } |
389 | 389 | |
390 | - if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
391 | - include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
390 | + if (defined('WP_ALL_IMPORT_ROOT_DIR')) { |
|
391 | + include plugin_dir_path(__FILE__) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
392 | 392 | } |
393 | 393 | } |
394 | 394 | |
@@ -400,24 +400,24 @@ discard block |
||
400 | 400 | */ |
401 | 401 | public function maybe_do_authenticated_action() { |
402 | 402 | |
403 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
403 | + if (isset($_REQUEST['getpaid-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
404 | 404 | |
405 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
406 | - $data = wp_unslash( $_REQUEST ); |
|
407 | - if ( is_user_logged_in() ) { |
|
408 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
405 | + $key = sanitize_key($_REQUEST['getpaid-action']); |
|
406 | + $data = wp_unslash($_REQUEST); |
|
407 | + if (is_user_logged_in()) { |
|
408 | + do_action("getpaid_authenticated_action_$key", $data); |
|
409 | 409 | } |
410 | 410 | |
411 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
411 | + do_action("getpaid_unauthenticated_action_$key", $data); |
|
412 | 412 | |
413 | 413 | } |
414 | 414 | |
415 | 415 | } |
416 | 416 | |
417 | - public function pre_get_posts( $wp_query ) { |
|
417 | + public function pre_get_posts($wp_query) { |
|
418 | 418 | |
419 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
420 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
419 | + if (!is_admin() && !empty($wp_query->query_vars['post_type']) && getpaid_is_invoice_post_type($wp_query->query_vars['post_type']) && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
420 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses(false, false, $wp_query->query_vars['post_type'])); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | return $wp_query; |
@@ -432,18 +432,18 @@ discard block |
||
432 | 432 | |
433 | 433 | // Currently, UX Builder does not work particulaly well with SuperDuper. |
434 | 434 | // So we disable our widgets when editing a page with UX Builder. |
435 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
435 | + if (function_exists('ux_builder_is_active') && ux_builder_is_active()) { |
|
436 | 436 | return; |
437 | 437 | } |
438 | 438 | |
439 | - $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
439 | + $block_widget_init_screens = function_exists('sd_pagenow_exclude') ? sd_pagenow_exclude() : array(); |
|
440 | 440 | |
441 | - if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
441 | + if (is_admin() && $pagenow && in_array($pagenow, $block_widget_init_screens)) { |
|
442 | 442 | // don't initiate in these conditions. |
443 | 443 | } else { |
444 | 444 | |
445 | 445 | // Only load allowed widgets. |
446 | - $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
446 | + $exclude = function_exists('sd_widget_exclude') ? sd_widget_exclude() : array(); |
|
447 | 447 | $widgets = apply_filters( |
448 | 448 | 'getpaid_widget_classes', |
449 | 449 | array( |
@@ -459,16 +459,16 @@ discard block |
||
459 | 459 | ); |
460 | 460 | |
461 | 461 | // For each widget... |
462 | - foreach ( $widgets as $widget ) { |
|
462 | + foreach ($widgets as $widget) { |
|
463 | 463 | |
464 | 464 | // Abort early if it is excluded for this page. |
465 | - if ( in_array( $widget, $exclude ) ) { |
|
465 | + if (in_array($widget, $exclude)) { |
|
466 | 466 | continue; |
467 | 467 | } |
468 | 468 | |
469 | 469 | // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
470 | - if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
471 | - register_widget( $widget ); |
|
470 | + if (is_subclass_of($widget, 'WP_Widget')) { |
|
471 | + register_widget($widget); |
|
472 | 472 | } else { |
473 | 473 | new $widget(); |
474 | 474 | } |
@@ -484,29 +484,29 @@ discard block |
||
484 | 484 | */ |
485 | 485 | public function maybe_upgrade_database() { |
486 | 486 | |
487 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
487 | + $wpi_version = get_option('wpinv_version', 0); |
|
488 | 488 | |
489 | - if ( $wpi_version == WPINV_VERSION ) { |
|
489 | + if ($wpi_version == WPINV_VERSION) { |
|
490 | 490 | return; |
491 | 491 | } |
492 | 492 | |
493 | 493 | $installer = new GetPaid_Installer(); |
494 | 494 | |
495 | - if ( empty( $wpi_version ) ) { |
|
496 | - return $installer->upgrade_db( 0 ); |
|
495 | + if (empty($wpi_version)) { |
|
496 | + return $installer->upgrade_db(0); |
|
497 | 497 | } |
498 | 498 | |
499 | - $upgrades = array( |
|
499 | + $upgrades = array( |
|
500 | 500 | '0.0.5' => '004', |
501 | 501 | '1.0.3' => '102', |
502 | 502 | '2.0.0' => '118', |
503 | 503 | '2.0.8' => '207', |
504 | 504 | ); |
505 | 505 | |
506 | - foreach ( $upgrades as $key => $method ) { |
|
506 | + foreach ($upgrades as $key => $method) { |
|
507 | 507 | |
508 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
509 | - return $installer->upgrade_db( $method ); |
|
508 | + if (version_compare($wpi_version, $key, '<')) { |
|
509 | + return $installer->upgrade_db($method); |
|
510 | 510 | } |
511 | 511 | } |
512 | 512 | |
@@ -519,11 +519,11 @@ discard block |
||
519 | 519 | */ |
520 | 520 | public function maybe_flush_permalinks() { |
521 | 521 | |
522 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
522 | + $flush = get_option('wpinv_flush_permalinks', 0); |
|
523 | 523 | |
524 | - if ( ! empty( $flush ) ) { |
|
524 | + if (!empty($flush)) { |
|
525 | 525 | flush_rewrite_rules(); |
526 | - delete_option( 'wpinv_flush_permalinks' ); |
|
526 | + delete_option('wpinv_flush_permalinks'); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | } |
@@ -534,10 +534,10 @@ discard block |
||
534 | 534 | * @since 1.0.19 |
535 | 535 | * @param int[] $excluded_posts_ids |
536 | 536 | */ |
537 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
537 | + public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) { |
|
538 | 538 | |
539 | 539 | // Ensure that we have an array. |
540 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
540 | + if (!is_array($excluded_posts_ids)) { |
|
541 | 541 | $excluded_posts_ids = array(); |
542 | 542 | } |
543 | 543 | |
@@ -545,24 +545,24 @@ discard block |
||
545 | 545 | $our_pages = array(); |
546 | 546 | |
547 | 547 | // Checkout page. |
548 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
548 | + $our_pages[] = wpinv_get_option('checkout_page', false); |
|
549 | 549 | |
550 | 550 | // Success page. |
551 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
551 | + $our_pages[] = wpinv_get_option('success_page', false); |
|
552 | 552 | |
553 | 553 | // Failure page. |
554 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
554 | + $our_pages[] = wpinv_get_option('failure_page', false); |
|
555 | 555 | |
556 | 556 | // History page. |
557 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
557 | + $our_pages[] = wpinv_get_option('invoice_history_page', false); |
|
558 | 558 | |
559 | 559 | // Subscriptions page. |
560 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
560 | + $our_pages[] = wpinv_get_option('invoice_subscription_page', false); |
|
561 | 561 | |
562 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
562 | + $our_pages = array_map('intval', array_filter($our_pages)); |
|
563 | 563 | |
564 | 564 | $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
565 | - return array_unique( $excluded_posts_ids ); |
|
565 | + return array_unique($excluded_posts_ids); |
|
566 | 566 | |
567 | 567 | } |
568 | 568 | |
@@ -572,7 +572,7 @@ discard block |
||
572 | 572 | * @since 2.0.0 |
573 | 573 | */ |
574 | 574 | public function wp_footer() { |
575 | - wpinv_get_template( 'frontend-footer.php' ); |
|
575 | + wpinv_get_template('frontend-footer.php'); |
|
576 | 576 | } |
577 | 577 | |
578 | 578 | /** |
@@ -581,14 +581,14 @@ discard block |
||
581 | 581 | * @since 2.0.0 |
582 | 582 | */ |
583 | 583 | public function wp_head() { |
584 | - wpinv_get_template( 'frontend-head.php' ); |
|
584 | + wpinv_get_template('frontend-head.php'); |
|
585 | 585 | } |
586 | 586 | |
587 | 587 | /** |
588 | 588 | * Custom query vars. |
589 | 589 | * |
590 | 590 | */ |
591 | - public function custom_query_vars( $vars ) { |
|
591 | + public function custom_query_vars($vars) { |
|
592 | 592 | $vars[] = 'getpaid-ipn'; |
593 | 593 | return $vars; |
594 | 594 | } |
@@ -599,28 +599,28 @@ discard block |
||
599 | 599 | */ |
600 | 600 | public function add_rewrite_rule() { |
601 | 601 | $tag = 'getpaid-ipn'; |
602 | - add_rewrite_tag( "%$tag%", '([^&]+)' ); |
|
603 | - add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
|
602 | + add_rewrite_tag("%$tag%", '([^&]+)'); |
|
603 | + add_rewrite_rule("^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top'); |
|
604 | 604 | } |
605 | 605 | |
606 | 606 | /** |
607 | 607 | * Processes non-query string ipns. |
608 | 608 | * |
609 | 609 | */ |
610 | - public function maybe_process_new_ipn( $query ) { |
|
610 | + public function maybe_process_new_ipn($query) { |
|
611 | 611 | |
612 | - if ( is_admin() || ! $query->is_main_query() ) { |
|
612 | + if (is_admin() || !$query->is_main_query()) { |
|
613 | 613 | return; |
614 | 614 | } |
615 | 615 | |
616 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
616 | + $gateway = get_query_var('getpaid-ipn'); |
|
617 | 617 | |
618 | - if ( ! empty( $gateway ) ) { |
|
618 | + if (!empty($gateway)) { |
|
619 | 619 | |
620 | - $gateway = sanitize_text_field( $gateway ); |
|
620 | + $gateway = sanitize_text_field($gateway); |
|
621 | 621 | nocache_headers(); |
622 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
623 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
622 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
623 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
624 | 624 | exit; |
625 | 625 | |
626 | 626 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Personal data exporters. |
4 | 4 | */ |
5 | 5 | |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * WPInv_Privacy_Exporters Class. |
@@ -17,39 +17,39 @@ discard block |
||
17 | 17 | * @param int $page Page. |
18 | 18 | * @return array An array of invoice data in name value pairs |
19 | 19 | */ |
20 | - public static function customer_invoice_data_exporter( $email_address, $page ) { |
|
20 | + public static function customer_invoice_data_exporter($email_address, $page) { |
|
21 | 21 | $done = false; |
22 | 22 | $page = (int) $page; |
23 | 23 | $data_to_export = array(); |
24 | 24 | |
25 | - $user = get_user_by( 'email', $email_address ); |
|
26 | - if ( ! $user instanceof WP_User ) { |
|
25 | + $user = get_user_by('email', $email_address); |
|
26 | + if (!$user instanceof WP_User) { |
|
27 | 27 | return array( |
28 | 28 | 'data' => $data_to_export, |
29 | 29 | 'done' => true, |
30 | 30 | ); |
31 | 31 | } |
32 | 32 | |
33 | - $args = array( |
|
34 | - 'limit' => get_option( 'posts_per_page' ), |
|
33 | + $args = array( |
|
34 | + 'limit' => get_option('posts_per_page'), |
|
35 | 35 | 'page' => $page, |
36 | 36 | 'user' => $user->ID, |
37 | 37 | 'paginate' => false, |
38 | 38 | ); |
39 | 39 | |
40 | - $invoices = wpinv_get_invoices( $args ); |
|
40 | + $invoices = wpinv_get_invoices($args); |
|
41 | 41 | |
42 | - if ( 0 < count( $invoices ) ) { |
|
43 | - foreach ( $invoices as $invoice ) { |
|
42 | + if (0 < count($invoices)) { |
|
43 | + foreach ($invoices as $invoice) { |
|
44 | 44 | $data_to_export[] = array( |
45 | 45 | 'group_id' => 'customer_invoices', |
46 | - 'group_label' => __( 'GetPaid: Invoices', 'invoicing' ), |
|
47 | - 'group_description' => __( 'Customer invoices.', 'invoicing' ), |
|
46 | + 'group_label' => __('GetPaid: Invoices', 'invoicing'), |
|
47 | + 'group_description' => __('Customer invoices.', 'invoicing'), |
|
48 | 48 | 'item_id' => "wpinv-{$invoice->get_id()}", |
49 | - 'data' => self::get_customer_invoice_data( $invoice ), |
|
49 | + 'data' => self::get_customer_invoice_data($invoice), |
|
50 | 50 | ); |
51 | 51 | } |
52 | - $done = get_option( 'posts_per_page' ) > count( $invoices ); |
|
52 | + $done = get_option('posts_per_page') > count($invoices); |
|
53 | 53 | } else { |
54 | 54 | $done = true; |
55 | 55 | } |
@@ -67,116 +67,116 @@ discard block |
||
67 | 67 | * @param WPInv_Invoice $invoice invoice object. |
68 | 68 | * @return array |
69 | 69 | */ |
70 | - public static function get_customer_invoice_data( $invoice ) { |
|
70 | + public static function get_customer_invoice_data($invoice) { |
|
71 | 71 | |
72 | 72 | // Prepare basic properties. |
73 | 73 | $props_to_export = array( |
74 | 74 | 'number' => array( |
75 | - 'name' => __( 'Invoice Number', 'invoicing' ), |
|
75 | + 'name' => __('Invoice Number', 'invoicing'), |
|
76 | 76 | 'value' => $invoice->get_number(), |
77 | 77 | ), |
78 | 78 | 'created_date' => array( |
79 | - 'name' => __( 'Created Date', 'invoicing' ), |
|
79 | + 'name' => __('Created Date', 'invoicing'), |
|
80 | 80 | 'value' => $invoice->get_date_created(), |
81 | 81 | ), |
82 | 82 | 'due_date' => array( |
83 | - 'name' => __( 'Due Date', 'invoicing' ), |
|
83 | + 'name' => __('Due Date', 'invoicing'), |
|
84 | 84 | 'value' => $invoice->get_due_date(), |
85 | 85 | ), |
86 | 86 | 'items' => array( |
87 | - 'name' => __( 'Invoice Items', 'invoicing' ), |
|
88 | - 'value' => self::process_invoice_items( $invoice ), |
|
87 | + 'name' => __('Invoice Items', 'invoicing'), |
|
88 | + 'value' => self::process_invoice_items($invoice), |
|
89 | 89 | ), |
90 | 90 | 'discount' => array( |
91 | - 'name' => __( 'Invoice Discount', 'invoicing' ), |
|
92 | - 'value' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ), |
|
91 | + 'name' => __('Invoice Discount', 'invoicing'), |
|
92 | + 'value' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()), |
|
93 | 93 | ), |
94 | 94 | 'total' => array( |
95 | - 'name' => __( 'Invoice Total', 'invoicing' ), |
|
96 | - 'value' => wpinv_price( $invoice->get_total(), $invoice->get_currency() ), |
|
95 | + 'name' => __('Invoice Total', 'invoicing'), |
|
96 | + 'value' => wpinv_price($invoice->get_total(), $invoice->get_currency()), |
|
97 | 97 | ), |
98 | 98 | 'status' => array( |
99 | - 'name' => __( 'Invoice Status', 'invoicing' ), |
|
99 | + 'name' => __('Invoice Status', 'invoicing'), |
|
100 | 100 | 'value' => $invoice->get_status_nicename(), |
101 | 101 | ), |
102 | 102 | 'first_name' => array( |
103 | - 'name' => __( 'First Name', 'invoicing' ), |
|
103 | + 'name' => __('First Name', 'invoicing'), |
|
104 | 104 | 'value' => $invoice->get_first_name(), |
105 | 105 | ), |
106 | 106 | 'last_name' => array( |
107 | - 'name' => __( 'Last Name', 'invoicing' ), |
|
107 | + 'name' => __('Last Name', 'invoicing'), |
|
108 | 108 | 'value' => $invoice->get_last_name(), |
109 | 109 | ), |
110 | 110 | 'email' => array( |
111 | - 'name' => __( 'Email Address', 'invoicing' ), |
|
111 | + 'name' => __('Email Address', 'invoicing'), |
|
112 | 112 | 'value' => $invoice->get_email(), |
113 | 113 | ), |
114 | 114 | 'company' => array( |
115 | - 'name' => __( 'Company', 'invoicing' ), |
|
115 | + 'name' => __('Company', 'invoicing'), |
|
116 | 116 | 'value' => $invoice->get_company(), |
117 | 117 | ), |
118 | 118 | 'phone' => array( |
119 | - 'name' => __( 'Phone Number', 'invoicing' ), |
|
119 | + 'name' => __('Phone Number', 'invoicing'), |
|
120 | 120 | 'value' => $invoice->get_phone(), |
121 | 121 | ), |
122 | 122 | 'address' => array( |
123 | - 'name' => __( 'Address', 'invoicing' ), |
|
123 | + 'name' => __('Address', 'invoicing'), |
|
124 | 124 | 'value' => $invoice->get_address(), |
125 | 125 | ), |
126 | 126 | 'city' => array( |
127 | - 'name' => __( 'City', 'invoicing' ), |
|
127 | + 'name' => __('City', 'invoicing'), |
|
128 | 128 | 'value' => $invoice->get_city(), |
129 | 129 | ), |
130 | 130 | 'state' => array( |
131 | - 'name' => __( 'State', 'invoicing' ), |
|
131 | + 'name' => __('State', 'invoicing'), |
|
132 | 132 | 'value' => $invoice->get_state(), |
133 | 133 | ), |
134 | 134 | 'zip' => array( |
135 | - 'name' => __( 'Zip', 'invoicing' ), |
|
135 | + 'name' => __('Zip', 'invoicing'), |
|
136 | 136 | 'value' => $invoice->get_zip(), |
137 | 137 | ), |
138 | 138 | 'vat_number' => array( |
139 | - 'name' => __( 'VAT Number', 'invoicing' ), |
|
139 | + 'name' => __('VAT Number', 'invoicing'), |
|
140 | 140 | 'value' => $invoice->get_vat_number(), |
141 | 141 | ), |
142 | 142 | 'description' => array( |
143 | - 'name' => __( 'Description', 'invoicing' ), |
|
143 | + 'name' => __('Description', 'invoicing'), |
|
144 | 144 | 'value' => $invoice->get_description(), |
145 | 145 | ), |
146 | 146 | ); |
147 | 147 | |
148 | 148 | // In case the invoice is paid, add the payment date and gateway. |
149 | - if ( $invoice->is_paid() ) { |
|
149 | + if ($invoice->is_paid()) { |
|
150 | 150 | |
151 | 151 | $props_to_export['completed_date'] = array( |
152 | - 'name' => __( 'Completed Date', 'invoicing' ), |
|
152 | + 'name' => __('Completed Date', 'invoicing'), |
|
153 | 153 | 'value' => $invoice->get_completed_date(), |
154 | 154 | ); |
155 | 155 | |
156 | 156 | $props_to_export['gateway'] = array( |
157 | - 'name' => __( 'Paid Via', 'invoicing' ), |
|
157 | + 'name' => __('Paid Via', 'invoicing'), |
|
158 | 158 | 'value' => $invoice->get_gateway(), |
159 | 159 | ); |
160 | 160 | |
161 | 161 | } |
162 | 162 | |
163 | 163 | // Maybe add subscription details. |
164 | - $props_to_export = self::process_subscription( $invoice, $props_to_export ); |
|
164 | + $props_to_export = self::process_subscription($invoice, $props_to_export); |
|
165 | 165 | |
166 | 166 | // Add the ip address. |
167 | 167 | $props_to_export['ip'] = array( |
168 | - 'name' => __( 'IP Address', 'invoicing' ), |
|
168 | + 'name' => __('IP Address', 'invoicing'), |
|
169 | 169 | 'value' => $invoice->get_ip(), |
170 | 170 | ); |
171 | 171 | |
172 | 172 | // Add the invoice url. |
173 | 173 | $props_to_export['view_url'] = array( |
174 | - 'name' => __( 'Invoice URL', 'invoicing' ), |
|
174 | + 'name' => __('Invoice URL', 'invoicing'), |
|
175 | 175 | 'value' => $invoice->get_view_url(), |
176 | 176 | ); |
177 | 177 | |
178 | 178 | // Return the values. |
179 | - return apply_filters( 'getpaid_privacy_export_invoice_personal_data', array_values( $props_to_export ), $invoice ); |
|
179 | + return apply_filters('getpaid_privacy_export_invoice_personal_data', array_values($props_to_export), $invoice); |
|
180 | 180 | |
181 | 181 | } |
182 | 182 | |
@@ -188,40 +188,40 @@ discard block |
||
188 | 188 | * @param array $props invoice props. |
189 | 189 | * @return array |
190 | 190 | */ |
191 | - public static function process_subscription( $invoice, $props ) { |
|
191 | + public static function process_subscription($invoice, $props) { |
|
192 | 192 | |
193 | - $subscription = wpinv_get_subscription( $invoice ); |
|
194 | - if ( ! empty( $subscription ) ) { |
|
193 | + $subscription = wpinv_get_subscription($invoice); |
|
194 | + if (!empty($subscription)) { |
|
195 | 195 | |
196 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency() ); |
|
197 | - $period = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ) . ' / ' . $frequency; |
|
198 | - $initial_amt = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
199 | - $bill_times = $subscription->get_times_billed() . ' / ' . ( ( $subscription->get_bill_times() == 0 ) ? __( 'Until Cancelled', 'invoicing' ) : $subscription->get_bill_times() ); |
|
200 | - $renewal_date = getpaid_format_date_value( $subscription->get_expiration() ); |
|
196 | + $frequency = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency()); |
|
197 | + $period = wpinv_price($subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency()) . ' / ' . $frequency; |
|
198 | + $initial_amt = wpinv_price($subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency()); |
|
199 | + $bill_times = $subscription->get_times_billed() . ' / ' . (($subscription->get_bill_times() == 0) ? __('Until Cancelled', 'invoicing') : $subscription->get_bill_times()); |
|
200 | + $renewal_date = getpaid_format_date_value($subscription->get_expiration()); |
|
201 | 201 | |
202 | 202 | // Billing cycle. |
203 | 203 | $props['period'] = array( |
204 | - 'name' => __( 'Billing Cycle', 'invoicing' ), |
|
204 | + 'name' => __('Billing Cycle', 'invoicing'), |
|
205 | 205 | 'value' => $period, |
206 | 206 | ); |
207 | 207 | |
208 | 208 | // Initial amount. |
209 | 209 | $props['initial_amount'] = array( |
210 | - 'name' => __( 'Initial Amount', 'invoicing' ), |
|
210 | + 'name' => __('Initial Amount', 'invoicing'), |
|
211 | 211 | 'value' => $initial_amt, |
212 | 212 | ); |
213 | 213 | |
214 | 214 | // Bill times. |
215 | 215 | $props['bill_times'] = array( |
216 | - 'name' => __( 'Times Billed', 'invoicing' ), |
|
216 | + 'name' => __('Times Billed', 'invoicing'), |
|
217 | 217 | 'value' => $bill_times, |
218 | 218 | ); |
219 | 219 | |
220 | 220 | // Add expiry date. |
221 | - if ( $subscription->is_active() ) { |
|
221 | + if ($subscription->is_active()) { |
|
222 | 222 | |
223 | 223 | $props['renewal_date'] = array( |
224 | - 'name' => __( 'Expires', 'invoicing' ), |
|
224 | + 'name' => __('Expires', 'invoicing'), |
|
225 | 225 | 'value' => $renewal_date, |
226 | 226 | ); |
227 | 227 | |
@@ -239,19 +239,19 @@ discard block |
||
239 | 239 | * @param WPInv_Invoice $invoice invoice object. |
240 | 240 | * @return array |
241 | 241 | */ |
242 | - public static function process_invoice_items( $invoice ) { |
|
242 | + public static function process_invoice_items($invoice) { |
|
243 | 243 | |
244 | 244 | $item_names = array(); |
245 | - foreach ( $invoice->get_items() as $cart_item ) { |
|
245 | + foreach ($invoice->get_items() as $cart_item) { |
|
246 | 246 | $item_names[] = sprintf( |
247 | 247 | '%s x %s - %s', |
248 | 248 | $cart_item->get_name(), |
249 | 249 | $cart_item->get_quantity(), |
250 | - wpinv_price( $invoice->is_renewal() ? $cart_item->get_recurring_sub_total() : $cart_item->get_sub_total(), $invoice->get_currency() ) |
|
250 | + wpinv_price($invoice->is_renewal() ? $cart_item->get_recurring_sub_total() : $cart_item->get_sub_total(), $invoice->get_currency()) |
|
251 | 251 | ); |
252 | 252 | } |
253 | 253 | |
254 | - return implode( ', ', $item_names ); |
|
254 | + return implode(', ', $item_names); |
|
255 | 255 | |
256 | 256 | } |
257 | 257 |
@@ -1,155 +1,155 @@ discard block |
||
1 | 1 | <?php |
2 | -function wpinv_is_subscription_payment( $invoice = '' ) { |
|
3 | - if ( empty( $invoice ) ) { |
|
2 | +function wpinv_is_subscription_payment($invoice = '') { |
|
3 | + if (empty($invoice)) { |
|
4 | 4 | return false; |
5 | 5 | } |
6 | 6 | |
7 | - if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
8 | - $invoice = wpinv_get_invoice( $invoice ); |
|
7 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
8 | + $invoice = wpinv_get_invoice($invoice); |
|
9 | 9 | } |
10 | 10 | |
11 | - if ( empty( $invoice ) ) { |
|
11 | + if (empty($invoice)) { |
|
12 | 12 | return false; |
13 | 13 | } |
14 | 14 | |
15 | - if ( $invoice->is_renewal() ) { |
|
15 | + if ($invoice->is_renewal()) { |
|
16 | 16 | return true; |
17 | 17 | } |
18 | 18 | |
19 | 19 | return false; |
20 | 20 | } |
21 | 21 | |
22 | -function wpinv_payment_link_transaction_id( $invoice = '' ) { |
|
23 | - if ( empty( $invoice ) ) { |
|
22 | +function wpinv_payment_link_transaction_id($invoice = '') { |
|
23 | + if (empty($invoice)) { |
|
24 | 24 | return false; |
25 | 25 | } |
26 | 26 | |
27 | - if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
28 | - $invoice = wpinv_get_invoice( $invoice ); |
|
27 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
28 | + $invoice = wpinv_get_invoice($invoice); |
|
29 | 29 | } |
30 | 30 | |
31 | - if ( empty( $invoice ) ) { |
|
31 | + if (empty($invoice)) { |
|
32 | 32 | return false; |
33 | 33 | } |
34 | 34 | |
35 | - return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice ); |
|
35 | + return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice); |
|
36 | 36 | } |
37 | 37 | |
38 | -function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) { |
|
39 | - $interval = (int)$interval > 0 ? (int)$interval : 1; |
|
38 | +function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) { |
|
39 | + $interval = (int) $interval > 0 ? (int) $interval : 1; |
|
40 | 40 | |
41 | - if ( $trial_interval > 0 && ! empty( $trial_period ) ) { |
|
42 | - $amount = __( 'Free', 'invoicing' ); |
|
41 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
42 | + $amount = __('Free', 'invoicing'); |
|
43 | 43 | $interval = $trial_interval; |
44 | 44 | $period = $trial_period; |
45 | 45 | } |
46 | 46 | |
47 | 47 | $description = ''; |
48 | - switch ( $period ) { |
|
48 | + switch ($period) { |
|
49 | 49 | case 'D': |
50 | 50 | case 'day': |
51 | - $description = wp_sprintf( _n( '%s for the first day.', '%1$s for the first %2$d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
51 | + $description = wp_sprintf(_n('%s for the first day.', '%1$s for the first %2$d days.', $interval, 'invoicing'), $amount, $interval); |
|
52 | 52 | break; |
53 | 53 | case 'W': |
54 | 54 | case 'week': |
55 | - $description = wp_sprintf( _n( '%s for the first week.', '%1$s for the first %2$d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
55 | + $description = wp_sprintf(_n('%s for the first week.', '%1$s for the first %2$d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
56 | 56 | break; |
57 | 57 | case 'M': |
58 | 58 | case 'month': |
59 | - $description = wp_sprintf( _n( '%s for the first month.', '%1$s for the first %2$d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
59 | + $description = wp_sprintf(_n('%s for the first month.', '%1$s for the first %2$d months.', $interval, 'invoicing'), $amount, $interval); |
|
60 | 60 | break; |
61 | 61 | case 'Y': |
62 | 62 | case 'year': |
63 | - $description = wp_sprintf( _n( '%s for the first year.', '%1$s for the first %2$d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
63 | + $description = wp_sprintf(_n('%s for the first year.', '%1$s for the first %2$d years.', $interval, 'invoicing'), $amount, $interval); |
|
64 | 64 | break; |
65 | 65 | } |
66 | 66 | |
67 | - return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval ); |
|
67 | + return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval); |
|
68 | 68 | } |
69 | 69 | |
70 | -function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) { |
|
71 | - $interval = (int)$interval > 0 ? (int)$interval : 1; |
|
72 | - $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0; |
|
70 | +function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) { |
|
71 | + $interval = (int) $interval > 0 ? (int) $interval : 1; |
|
72 | + $bill_times = (int) $bill_times > 0 ? (int) $bill_times : 0; |
|
73 | 73 | |
74 | 74 | $description = ''; |
75 | - switch ( $period ) { |
|
75 | + switch ($period) { |
|
76 | 76 | case 'D': |
77 | 77 | case 'day': |
78 | - if ( (int)$bill_times > 0 ) { |
|
79 | - if ( $interval > 1 ) { |
|
80 | - if ( $bill_times > 1 ) { |
|
81 | - $description = wp_sprintf( __( '%1$s for each %2$d days, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
78 | + if ((int) $bill_times > 0) { |
|
79 | + if ($interval > 1) { |
|
80 | + if ($bill_times > 1) { |
|
81 | + $description = wp_sprintf(__('%1$s for each %2$d days, for %3$d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
82 | 82 | } else { |
83 | - $description = wp_sprintf( __( '%1$s for %2$d days.', 'invoicing' ), $amount, $interval ); |
|
83 | + $description = wp_sprintf(__('%1$s for %2$d days.', 'invoicing'), $amount, $interval); |
|
84 | 84 | } |
85 | 85 | } else { |
86 | - $description = wp_sprintf( _n( '%s for one day.', '%1$s for each day, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
86 | + $description = wp_sprintf(_n('%s for one day.', '%1$s for each day, for %2$d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
87 | 87 | } |
88 | 88 | } else { |
89 | - $description = wp_sprintf( _n( '%s for each day.', '%1$s for each %2$d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
89 | + $description = wp_sprintf(_n('%s for each day.', '%1$s for each %2$d days.', $interval, 'invoicing'), $amount, $interval); |
|
90 | 90 | } |
91 | 91 | break; |
92 | 92 | case 'W': |
93 | 93 | case 'week': |
94 | - if ( (int)$bill_times > 0 ) { |
|
95 | - if ( $interval > 1 ) { |
|
96 | - if ( $bill_times > 1 ) { |
|
97 | - $description = wp_sprintf( __( '%1$s for each %2$d weeks, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
94 | + if ((int) $bill_times > 0) { |
|
95 | + if ($interval > 1) { |
|
96 | + if ($bill_times > 1) { |
|
97 | + $description = wp_sprintf(__('%1$s for each %2$d weeks, for %3$d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
98 | 98 | } else { |
99 | - $description = wp_sprintf( __( '%1$s for %2$d weeks.', 'invoicing' ), $amount, $interval ); |
|
99 | + $description = wp_sprintf(__('%1$s for %2$d weeks.', 'invoicing'), $amount, $interval); |
|
100 | 100 | } |
101 | 101 | } else { |
102 | - $description = wp_sprintf( _n( '%s for one week.', '%1$s for each week, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
102 | + $description = wp_sprintf(_n('%s for one week.', '%1$s for each week, for %2$d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
103 | 103 | } |
104 | 104 | } else { |
105 | - $description = wp_sprintf( _n( '%s for each week.', '%1$s for each %2$d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
105 | + $description = wp_sprintf(_n('%s for each week.', '%1$s for each %2$d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
106 | 106 | } |
107 | 107 | break; |
108 | 108 | case 'M': |
109 | 109 | case 'month': |
110 | - if ( (int)$bill_times > 0 ) { |
|
111 | - if ( $interval > 1 ) { |
|
112 | - if ( $bill_times > 1 ) { |
|
113 | - $description = wp_sprintf( __( '%1$s for each %2$d months, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
110 | + if ((int) $bill_times > 0) { |
|
111 | + if ($interval > 1) { |
|
112 | + if ($bill_times > 1) { |
|
113 | + $description = wp_sprintf(__('%1$s for each %2$d months, for %3$d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
114 | 114 | } else { |
115 | - $description = wp_sprintf( __( '%1$s for %2$d months.', 'invoicing' ), $amount, $interval ); |
|
115 | + $description = wp_sprintf(__('%1$s for %2$d months.', 'invoicing'), $amount, $interval); |
|
116 | 116 | } |
117 | 117 | } else { |
118 | - $description = wp_sprintf( _n( '%s for one month.', '%1$s for each month, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
118 | + $description = wp_sprintf(_n('%s for one month.', '%1$s for each month, for %2$d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
119 | 119 | } |
120 | 120 | } else { |
121 | - $description = wp_sprintf( _n( '%s for each month.', '%1$s for each %2$d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
121 | + $description = wp_sprintf(_n('%s for each month.', '%1$s for each %2$d months.', $interval, 'invoicing'), $amount, $interval); |
|
122 | 122 | } |
123 | 123 | break; |
124 | 124 | case 'Y': |
125 | 125 | case 'year': |
126 | - if ( (int)$bill_times > 0 ) { |
|
127 | - if ( $interval > 1 ) { |
|
128 | - if ( $bill_times > 1 ) { |
|
129 | - $description = wp_sprintf( __( '%1$s for each %2$d years, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
126 | + if ((int) $bill_times > 0) { |
|
127 | + if ($interval > 1) { |
|
128 | + if ($bill_times > 1) { |
|
129 | + $description = wp_sprintf(__('%1$s for each %2$d years, for %3$d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
130 | 130 | } else { |
131 | - $description = wp_sprintf( __( '%1$s for %2$d years.', 'invoicing' ), $amount, $interval ); |
|
131 | + $description = wp_sprintf(__('%1$s for %2$d years.', 'invoicing'), $amount, $interval); |
|
132 | 132 | } |
133 | 133 | } else { |
134 | - $description = wp_sprintf( _n( '%s for one year.', '%1$s for each year, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
134 | + $description = wp_sprintf(_n('%s for one year.', '%1$s for each year, for %2$d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
135 | 135 | } |
136 | 136 | } else { |
137 | - $description = wp_sprintf( _n( '%s for each year.', '%1$s for each %2$d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
137 | + $description = wp_sprintf(_n('%s for each year.', '%1$s for each %2$d years.', $interval, 'invoicing'), $amount, $interval); |
|
138 | 138 | } |
139 | 139 | break; |
140 | 140 | } |
141 | 141 | |
142 | - return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
142 | + return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
143 | 143 | } |
144 | 144 | |
145 | -function wpinv_subscription_payment_desc( $invoice ) { |
|
146 | - if ( empty( $invoice ) ) { |
|
145 | +function wpinv_subscription_payment_desc($invoice) { |
|
146 | + if (empty($invoice)) { |
|
147 | 147 | return null; |
148 | 148 | } |
149 | 149 | |
150 | 150 | $description = ''; |
151 | - if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) { |
|
152 | - if ( $item->has_free_trial() ) { |
|
151 | + if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) { |
|
152 | + if ($item->has_free_trial()) { |
|
153 | 153 | $trial_period = $item->get_trial_period(); |
154 | 154 | $trial_interval = $item->get_trial_interval(); |
155 | 155 | } else { |
@@ -157,40 +157,40 @@ discard block |
||
157 | 157 | $trial_interval = 0; |
158 | 158 | } |
159 | 159 | |
160 | - $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() ); |
|
160 | + $description = wpinv_get_billing_cycle($invoice->get_total(), $invoice->get_recurring_details('total'), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency()); |
|
161 | 161 | } |
162 | 162 | |
163 | - return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice ); |
|
163 | + return apply_filters('wpinv_subscription_payment_desc', $description, $invoice); |
|
164 | 164 | } |
165 | 165 | |
166 | -function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) { |
|
167 | - $initial_total = wpinv_round_amount( $initial ); |
|
168 | - $recurring_total = wpinv_round_amount( $recurring ); |
|
166 | +function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') { |
|
167 | + $initial_total = wpinv_round_amount($initial); |
|
168 | + $recurring_total = wpinv_round_amount($recurring); |
|
169 | 169 | |
170 | - if ( $trial_interval > 0 && ! empty( $trial_period ) ) { |
|
170 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
171 | 171 | // Free trial |
172 | 172 | } else { |
173 | - if ( $bill_times == 1 ) { |
|
173 | + if ($bill_times == 1) { |
|
174 | 174 | $recurring_total = $initial_total; |
175 | - } elseif ( $bill_times > 1 && $initial_total != $recurring_total ) { |
|
175 | + } elseif ($bill_times > 1 && $initial_total != $recurring_total) { |
|
176 | 176 | $bill_times--; |
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
180 | - $initial_amount = wpinv_price( $initial_total, $currency ); |
|
181 | - $recurring_amount = wpinv_price( $recurring_total, $currency ); |
|
180 | + $initial_amount = wpinv_price($initial_total, $currency); |
|
181 | + $recurring_amount = wpinv_price($recurring_total, $currency); |
|
182 | 182 | |
183 | - $recurring = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
183 | + $recurring = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
184 | 184 | |
185 | - if ( $initial_total != $recurring_total ) { |
|
186 | - $initial = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval ); |
|
185 | + if ($initial_total != $recurring_total) { |
|
186 | + $initial = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval); |
|
187 | 187 | |
188 | - $description = wp_sprintf( __( '%1$s Then %2$s', 'invoicing' ), $initial, $recurring ); |
|
188 | + $description = wp_sprintf(__('%1$s Then %2$s', 'invoicing'), $initial, $recurring); |
|
189 | 189 | } else { |
190 | 190 | $description = $recurring; |
191 | 191 | } |
192 | 192 | |
193 | - return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency ); |
|
193 | + return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -200,27 +200,27 @@ discard block |
||
200 | 200 | * @param string $card_number Card number. |
201 | 201 | * @return string |
202 | 202 | */ |
203 | -function getpaid_get_card_name( $card_number ) { |
|
203 | +function getpaid_get_card_name($card_number) { |
|
204 | 204 | |
205 | 205 | // Known regexes. |
206 | 206 | $regexes = array( |
207 | - '/^4/' => __( 'Visa', 'invoicing' ), |
|
208 | - '/^5[1-5]/' => __( 'Mastercard', 'invoicing' ), |
|
209 | - '/^3[47]/' => __( 'Amex', 'invoicing' ), |
|
210 | - '/^3(?:0[0-5]|[68])/' => __( 'Diners Club', 'invoicing' ), |
|
211 | - '/^6(?:011|5)/' => __( 'Discover', 'invoicing' ), |
|
212 | - '/^(?:2131|1800|35\d{3})/' => __( 'JCB', 'invoicing' ), |
|
207 | + '/^4/' => __('Visa', 'invoicing'), |
|
208 | + '/^5[1-5]/' => __('Mastercard', 'invoicing'), |
|
209 | + '/^3[47]/' => __('Amex', 'invoicing'), |
|
210 | + '/^3(?:0[0-5]|[68])/' => __('Diners Club', 'invoicing'), |
|
211 | + '/^6(?:011|5)/' => __('Discover', 'invoicing'), |
|
212 | + '/^(?:2131|1800|35\d{3})/' => __('JCB', 'invoicing'), |
|
213 | 213 | ); |
214 | 214 | |
215 | 215 | // Confirm if one matches. |
216 | - foreach ( $regexes as $regex => $card ) { |
|
217 | - if ( preg_match( $regex, $card_number ) >= 1 ) { |
|
216 | + foreach ($regexes as $regex => $card) { |
|
217 | + if (preg_match($regex, $card_number) >= 1) { |
|
218 | 218 | return $card; |
219 | 219 | } |
220 | 220 | } |
221 | 221 | |
222 | 222 | // None matched. |
223 | - return __( 'Card', 'invoicing' ); |
|
223 | + return __('Card', 'invoicing'); |
|
224 | 224 | |
225 | 225 | } |
226 | 226 | |
@@ -229,23 +229,23 @@ discard block |
||
229 | 229 | * |
230 | 230 | * @param WPInv_Invoice|int|null $invoice |
231 | 231 | */ |
232 | -function wpinv_send_back_to_checkout( $invoice = null ) { |
|
233 | - $response = array( 'success' => false ); |
|
234 | - $invoice = wpinv_get_invoice( $invoice ); |
|
232 | +function wpinv_send_back_to_checkout($invoice = null) { |
|
233 | + $response = array('success' => false); |
|
234 | + $invoice = wpinv_get_invoice($invoice); |
|
235 | 235 | |
236 | 236 | // Was an invoice created? |
237 | - if ( ! empty( $invoice ) ) { |
|
238 | - $invoice = is_scalar( $invoice ) ? new WPInv_Invoice( $invoice ) : $invoice; |
|
237 | + if (!empty($invoice)) { |
|
238 | + $invoice = is_scalar($invoice) ? new WPInv_Invoice($invoice) : $invoice; |
|
239 | 239 | $response['invoice'] = $invoice->get_id(); |
240 | - do_action( 'getpaid_checkout_invoice_exception', $invoice ); |
|
240 | + do_action('getpaid_checkout_invoice_exception', $invoice); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | // Do we have any errors? |
244 | - if ( wpinv_get_errors() ) { |
|
245 | - $response['data'] = getpaid_get_errors_html( true, false ); |
|
244 | + if (wpinv_get_errors()) { |
|
245 | + $response['data'] = getpaid_get_errors_html(true, false); |
|
246 | 246 | } else { |
247 | - $response['data'] = __( 'An error occured while processing your payment. Please try again.', 'invoicing' ); |
|
247 | + $response['data'] = __('An error occured while processing your payment. Please try again.', 'invoicing'); |
|
248 | 248 | } |
249 | 249 | |
250 | - wp_send_json( $response ); |
|
250 | + wp_send_json($response); |
|
251 | 251 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Returns an array of discount type. |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | return apply_filters( |
18 | 18 | 'wpinv_discount_types', |
19 | 19 | array( |
20 | - 'percent' => __( 'Percentage', 'invoicing' ), |
|
21 | - 'flat' => __( 'Flat Amount', 'invoicing' ), |
|
20 | + 'percent' => __('Percentage', 'invoicing'), |
|
21 | + 'flat' => __('Flat Amount', 'invoicing'), |
|
22 | 22 | ) |
23 | 23 | ); |
24 | 24 | } |
@@ -28,46 +28,46 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @return string |
30 | 30 | */ |
31 | -function wpinv_get_discount_type_name( $type = '' ) { |
|
31 | +function wpinv_get_discount_type_name($type = '') { |
|
32 | 32 | $types = wpinv_get_discount_types(); |
33 | - return isset( $types[ $type ] ) ? $types[ $type ] : $type; |
|
33 | + return isset($types[$type]) ? $types[$type] : $type; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Deletes a discount via the admin page. |
38 | 38 | * |
39 | 39 | */ |
40 | -function wpinv_delete_discount( $data ) { |
|
40 | +function wpinv_delete_discount($data) { |
|
41 | 41 | |
42 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
43 | - $discount->delete( true ); |
|
42 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
43 | + $discount->delete(true); |
|
44 | 44 | |
45 | 45 | } |
46 | -add_action( 'getpaid_authenticated_admin_action_delete_discount', 'wpinv_delete_discount' ); |
|
46 | +add_action('getpaid_authenticated_admin_action_delete_discount', 'wpinv_delete_discount'); |
|
47 | 47 | |
48 | 48 | /** |
49 | 49 | * Deactivates a discount via the admin page. |
50 | 50 | */ |
51 | -function wpinv_activate_discount( $data ) { |
|
51 | +function wpinv_activate_discount($data) { |
|
52 | 52 | |
53 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
54 | - $discount->set_status( 'publish' ); |
|
53 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
54 | + $discount->set_status('publish'); |
|
55 | 55 | $discount->save(); |
56 | 56 | |
57 | 57 | } |
58 | -add_action( 'getpaid_authenticated_admin_action_activate_discount', 'wpinv_activate_discount' ); |
|
58 | +add_action('getpaid_authenticated_admin_action_activate_discount', 'wpinv_activate_discount'); |
|
59 | 59 | |
60 | 60 | /** |
61 | 61 | * Activates a discount via the admin page. |
62 | 62 | */ |
63 | -function wpinv_deactivate_discount( $data ) { |
|
63 | +function wpinv_deactivate_discount($data) { |
|
64 | 64 | |
65 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
66 | - $discount->set_status( 'pending' ); |
|
65 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
66 | + $discount->set_status('pending'); |
|
67 | 67 | $discount->save(); |
68 | 68 | |
69 | 69 | } |
70 | -add_action( 'getpaid_authenticated_admin_action_deactivate_discount', 'wpinv_deactivate_discount' ); |
|
70 | +add_action('getpaid_authenticated_admin_action_deactivate_discount', 'wpinv_deactivate_discount'); |
|
71 | 71 | |
72 | 72 | /** |
73 | 73 | * Fetches a discount object. |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | * @since 1.0.15 |
77 | 77 | * @return WPInv_Discount |
78 | 78 | */ |
79 | -function wpinv_get_discount( $discount ) { |
|
80 | - return new WPInv_Discount( $discount ); |
|
79 | +function wpinv_get_discount($discount) { |
|
80 | + return new WPInv_Discount($discount); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | * @since 1.0.15 |
88 | 88 | * @return WPInv_Discount |
89 | 89 | */ |
90 | -function wpinv_get_discount_obj( $discount = 0 ) { |
|
91 | - return new WPInv_Discount( $discount ); |
|
90 | +function wpinv_get_discount_obj($discount = 0) { |
|
91 | + return new WPInv_Discount($discount); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -98,10 +98,10 @@ discard block |
||
98 | 98 | * @param string|int $value The field value |
99 | 99 | * @return bool|WPInv_Discount |
100 | 100 | */ |
101 | -function wpinv_get_discount_by( $deprecated = null, $value = '' ) { |
|
102 | - $discount = new WPInv_Discount( $value ); |
|
101 | +function wpinv_get_discount_by($deprecated = null, $value = '') { |
|
102 | + $discount = new WPInv_Discount($value); |
|
103 | 103 | |
104 | - if ( $discount->get_id() != 0 ) { |
|
104 | + if ($discount->get_id() != 0) { |
|
105 | 105 | return $discount; |
106 | 106 | } |
107 | 107 | |
@@ -116,9 +116,9 @@ discard block |
||
116 | 116 | function wpinv_get_discount_statuses() { |
117 | 117 | |
118 | 118 | return array( |
119 | - 'expired' => __( 'Expired', 'invoicing' ), |
|
120 | - 'publish' => __( 'Active', 'invoicing' ), |
|
121 | - 'inactive' => __( 'Inactive', 'invoicing' ), |
|
119 | + 'expired' => __('Expired', 'invoicing'), |
|
120 | + 'publish' => __('Active', 'invoicing'), |
|
121 | + 'inactive' => __('Inactive', 'invoicing'), |
|
122 | 122 | ); |
123 | 123 | |
124 | 124 | } |
@@ -126,9 +126,9 @@ discard block |
||
126 | 126 | /** |
127 | 127 | * Retrieves an invoice status label. |
128 | 128 | */ |
129 | -function wpinv_discount_status( $status ) { |
|
129 | +function wpinv_discount_status($status) { |
|
130 | 130 | $statuses = wpinv_get_discount_statuses(); |
131 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : __( 'Inactive', 'invoicing' ); |
|
131 | + return isset($statuses[$status]) ? $statuses[$status] : __('Inactive', 'invoicing'); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | * @param int|array|string|WPInv_Discount $code discount data, object, ID or code. |
139 | 139 | * @return bool |
140 | 140 | */ |
141 | -function wpinv_discount_is_recurring( $discount = 0, $code = 0 ) { |
|
141 | +function wpinv_discount_is_recurring($discount = 0, $code = 0) { |
|
142 | 142 | |
143 | - if ( ! empty( $discount ) ) { |
|
144 | - $discount = wpinv_get_discount_obj( $discount ); |
|
143 | + if (!empty($discount)) { |
|
144 | + $discount = wpinv_get_discount_obj($discount); |
|
145 | 145 | } else { |
146 | - $discount = wpinv_get_discount_obj( $code ); |
|
146 | + $discount = wpinv_get_discount_obj($code); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | return $discount->get_is_recurring(); |
@@ -158,35 +158,35 @@ discard block |
||
158 | 158 | * @param WPInv_Discount $discount |
159 | 159 | * @return array |
160 | 160 | */ |
161 | -function getpaid_calculate_invoice_discount( $invoice, $discount ) { |
|
161 | +function getpaid_calculate_invoice_discount($invoice, $discount) { |
|
162 | 162 | |
163 | 163 | $initial_discount = 0; |
164 | 164 | $recurring_discount = 0; |
165 | 165 | |
166 | - foreach ( $invoice->get_items() as $item ) { |
|
166 | + foreach ($invoice->get_items() as $item) { |
|
167 | 167 | |
168 | 168 | // Abort if it is not valid for this item. |
169 | - if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
169 | + if (!$discount->is_valid_for_items(array($item->get_id()))) { |
|
170 | 170 | continue; |
171 | 171 | } |
172 | 172 | |
173 | 173 | // Calculate the initial amount... |
174 | - $item_discount = $discount->get_discounted_amount( $item->get_sub_total() ); |
|
174 | + $item_discount = $discount->get_discounted_amount($item->get_sub_total()); |
|
175 | 175 | $recurring_item_discount = 0; |
176 | 176 | |
177 | 177 | // ... and maybe the recurring amount. |
178 | - if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
179 | - $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
178 | + if ($item->is_recurring() && $discount->is_recurring()) { |
|
179 | + $recurring_item_discount = $discount->get_discounted_amount($item->get_recurring_sub_total()); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | // Discount should not exceed discounted amount. |
183 | - if ( ! $discount->is_type( 'percent' ) ) { |
|
183 | + if (!$discount->is_type('percent')) { |
|
184 | 184 | |
185 | - if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) { |
|
185 | + if (($initial_discount + $item_discount) > $discount->get_amount()) { |
|
186 | 186 | $item_discount = $discount->get_amount() - $initial_discount; |
187 | 187 | } |
188 | 188 | |
189 | - if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) { |
|
189 | + if (($recurring_discount + $recurring_item_discount) > $discount->get_amount()) { |
|
190 | 190 | $recurring_item_discount = $discount->get_amount() - $recurring_discount; |
191 | 191 | } |
192 | 192 | } |
@@ -218,10 +218,10 @@ discard block |
||
218 | 218 | array( |
219 | 219 | 'post_type' => 'wpi_discount', |
220 | 220 | 'numberposts' => 1, |
221 | - 'fields' => array( 'ids' ), |
|
221 | + 'fields' => array('ids'), |
|
222 | 222 | ) |
223 | 223 | ); |
224 | 224 | |
225 | - return ! empty( $discounts ); |
|
225 | + return !empty($discounts); |
|
226 | 226 | |
227 | 227 | } |
@@ -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 | * Handles invoice notes. |
@@ -18,18 +18,18 @@ discard block |
||
18 | 18 | public function __construct() { |
19 | 19 | |
20 | 20 | // Filter inovice notes. |
21 | - add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
22 | - add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 ); |
|
21 | + add_action('pre_get_comments', array($this, 'set_invoice_note_type'), 11, 1); |
|
22 | + add_action('comment_feed_where', array($this, 'wpinv_comment_feed_where'), 10, 1); |
|
23 | 23 | |
24 | 24 | // Delete comments count cache whenever there is a new comment or a comment status changes. |
25 | - add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) ); |
|
26 | - add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) ); |
|
25 | + add_action('wp_insert_comment', array($this, 'delete_comments_count_cache')); |
|
26 | + add_action('wp_set_comment_status', array($this, 'delete_comments_count_cache')); |
|
27 | 27 | |
28 | 28 | // Count comments. |
29 | - add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 ); |
|
29 | + add_filter('wp_count_comments', array($this, 'wp_count_comments'), 100, 2); |
|
30 | 30 | |
31 | 31 | // Fires after notes are loaded. |
32 | - do_action( 'wpinv_notes_init', $this ); |
|
32 | + do_action('wpinv_notes_init', $this); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -37,19 +37,19 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @param WP_Comment_Query $query |
39 | 39 | */ |
40 | - public function set_invoice_note_type( $query ) { |
|
41 | - $post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
40 | + public function set_invoice_note_type($query) { |
|
41 | + $post_id = !empty($query->query_vars['post_ID']) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
42 | 42 | |
43 | - if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) { |
|
43 | + if ($post_id && getpaid_is_invoice_post_type(get_post_type($post_id))) { |
|
44 | 44 | $query->query_vars['type'] = 'wpinv_note'; |
45 | 45 | } else { |
46 | 46 | |
47 | - if ( empty( $query->query_vars['type__not_in'] ) ) { |
|
47 | + if (empty($query->query_vars['type__not_in'])) { |
|
48 | 48 | $query->query_vars['type__not_in'] = array(); |
49 | 49 | } |
50 | 50 | |
51 | - $query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] ); |
|
52 | - $query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] ); |
|
51 | + $query->query_vars['type__not_in'] = wpinv_parse_list($query->query_vars['type__not_in']); |
|
52 | + $query->query_vars['type__not_in'] = array_merge(array('wpinv_note'), $query->query_vars['type__not_in']); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | return $query; |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | /** |
59 | 59 | * Exclude notes from the comments feed. |
60 | 60 | */ |
61 | - function wpinv_comment_feed_where( $where ) { |
|
62 | - return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' "; |
|
61 | + function wpinv_comment_feed_where($where) { |
|
62 | + return $where . ($where ? ' AND ' : '') . " comment_type != 'wpinv_note' "; |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * is called. |
70 | 70 | */ |
71 | 71 | public function delete_comments_count_cache() { |
72 | - delete_transient( 'getpaid_count_comments' ); |
|
72 | + delete_transient('getpaid_count_comments'); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -80,13 +80,13 @@ discard block |
||
80 | 80 | * @param int $post_id Post ID. |
81 | 81 | * @return object |
82 | 82 | */ |
83 | - public function wp_count_comments( $stats, $post_id ) { |
|
83 | + public function wp_count_comments($stats, $post_id) { |
|
84 | 84 | global $wpdb; |
85 | 85 | |
86 | - if ( empty( $post_id ) ) { |
|
87 | - $stats = get_transient( 'getpaid_count_comments' ); |
|
86 | + if (empty($post_id)) { |
|
87 | + $stats = get_transient('getpaid_count_comments'); |
|
88 | 88 | |
89 | - if ( ! $stats ) { |
|
89 | + if (!$stats) { |
|
90 | 90 | $stats = array( |
91 | 91 | 'total_comments' => 0, |
92 | 92 | 'all' => 0, |
@@ -110,27 +110,27 @@ discard block |
||
110 | 110 | 'post-trashed' => 'post-trashed', |
111 | 111 | ); |
112 | 112 | |
113 | - foreach ( (array) $count as $row ) { |
|
113 | + foreach ((array) $count as $row) { |
|
114 | 114 | // Don't count post-trashed toward totals. |
115 | - if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) { |
|
115 | + if (!in_array($row['comment_approved'], array('post-trashed', 'trash', 'spam'), true)) { |
|
116 | 116 | $stats['all'] += $row['num_comments']; |
117 | 117 | $stats['total_comments'] += $row['num_comments']; |
118 | - } elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) { |
|
118 | + } elseif (!in_array($row['comment_approved'], array('post-trashed', 'trash'), true)) { |
|
119 | 119 | $stats['total_comments'] += $row['num_comments']; |
120 | 120 | } |
121 | - if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
122 | - $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
121 | + if (isset($approved[$row['comment_approved']])) { |
|
122 | + $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
123 | 123 | } |
124 | 124 | } |
125 | 125 | |
126 | - foreach ( $approved as $key ) { |
|
127 | - if ( empty( $stats[ $key ] ) ) { |
|
128 | - $stats[ $key ] = 0; |
|
126 | + foreach ($approved as $key) { |
|
127 | + if (empty($stats[$key])) { |
|
128 | + $stats[$key] = 0; |
|
129 | 129 | } |
130 | 130 | } |
131 | 131 | |
132 | 132 | $stats = (object) $stats; |
133 | - set_transient( 'getpaid_count_comments', $stats ); |
|
133 | + set_transient('getpaid_count_comments', $stats); |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @param string $type Optional. Pass in customer to only return customer notes. |
145 | 145 | * @return WP_Comment[] |
146 | 146 | */ |
147 | - public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) { |
|
147 | + public function get_invoice_notes($invoice_id = 0, $type = 'all') { |
|
148 | 148 | |
149 | 149 | // Default comment args. |
150 | 150 | $args = array( |
@@ -154,14 +154,14 @@ discard block |
||
154 | 154 | ); |
155 | 155 | |
156 | 156 | // Maybe only show customer comments. |
157 | - if ( $type == 'customer' ) { |
|
157 | + if ($type == 'customer') { |
|
158 | 158 | $args['meta_key'] = '_wpi_customer_note'; |
159 | 159 | $args['meta_value'] = 1; |
160 | 160 | } |
161 | 161 | |
162 | - $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
162 | + $args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type); |
|
163 | 163 | |
164 | - return get_comments( $args ); |
|
164 | + return get_comments($args); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -173,9 +173,9 @@ discard block |
||
173 | 173 | * @param bool $for_customer Whether or not this comment is meant to be sent to the customer. |
174 | 174 | * @return int|false The new note's ID on success, false on failure. |
175 | 175 | */ |
176 | - function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ) { |
|
176 | + function add_invoice_note($invoice, $note, $note_author, $author_email, $for_customer = false) { |
|
177 | 177 | |
178 | - do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer ); |
|
178 | + do_action('wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer); |
|
179 | 179 | |
180 | 180 | /** |
181 | 181 | * Insert the comment. |
@@ -196,14 +196,14 @@ discard block |
||
196 | 196 | ) |
197 | 197 | ); |
198 | 198 | |
199 | - do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer ); |
|
199 | + do_action('wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer); |
|
200 | 200 | |
201 | 201 | // Are we notifying the customer? |
202 | - if ( empty( $note_id ) || empty( $for_customer ) ) { |
|
202 | + if (empty($note_id) || empty($for_customer)) { |
|
203 | 203 | return $note_id; |
204 | 204 | } |
205 | 205 | |
206 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
206 | + add_comment_meta($note_id, '_wpi_customer_note', 1); |
|
207 | 207 | do_action( |
208 | 208 | 'wpinv_new_customer_note', |
209 | 209 | array( |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | 'user_note' => $note, |
212 | 212 | ) |
213 | 213 | ); |
214 | - do_action( 'getpaid_new_customer_note', $invoice, $note ); |
|
214 | + do_action('getpaid_new_customer_note', $invoice, $note); |
|
215 | 215 | return $note_id; |
216 | 216 | } |
217 | 217 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | // Exit if accessed directly. |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Main GetPaid Class. |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @type array $meta_tables Optional. An array of metadata table names. |
56 | 56 | * } |
57 | 57 | */ |
58 | - public function setup_globals( $args = array() ) { |
|
58 | + public function setup_globals($args = array()) { |
|
59 | 59 | parent::setup_globals( |
60 | 60 | array( |
61 | 61 | 'id' => 'getpaid', |
@@ -76,30 +76,30 @@ discard block |
||
76 | 76 | * @param array $main_nav Optional. See BP_Component::setup_nav() for description. |
77 | 77 | * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. |
78 | 78 | */ |
79 | - public function setup_nav( $main_nav = array(), $sub_nav = array() ) { |
|
79 | + public function setup_nav($main_nav = array(), $sub_nav = array()) { |
|
80 | 80 | |
81 | 81 | // Abort if the integration is inactive. |
82 | - if ( ! getpaid_is_buddypress_integration_active() || ! is_user_logged_in() ) { |
|
82 | + if (!getpaid_is_buddypress_integration_active() || !is_user_logged_in()) { |
|
83 | 83 | return; |
84 | 84 | } |
85 | 85 | |
86 | 86 | // Or a user is not viewing their profile. |
87 | - if ( bp_displayed_user_id() != bp_loggedin_user_id() ) { |
|
87 | + if (bp_displayed_user_id() != bp_loggedin_user_id()) { |
|
88 | 88 | return; |
89 | 89 | } |
90 | 90 | |
91 | 91 | // Determine user to use. |
92 | 92 | $user_domain = bp_loggedin_user_domain(); |
93 | 93 | $slug = 'getpaid'; |
94 | - $payments_link = trailingslashit( $user_domain . $slug ); |
|
94 | + $payments_link = trailingslashit($user_domain . $slug); |
|
95 | 95 | |
96 | 96 | // Add 'Payments' to the main navigation. |
97 | 97 | $main_nav = array( |
98 | - 'name' => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ), |
|
98 | + 'name' => _x('Billing', 'BuddyPress profile payments screen nav', 'invoicing'), |
|
99 | 99 | 'slug' => $slug, |
100 | - 'position' => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ), |
|
101 | - 'screen_function' => array( $this, 'display_current_tab' ), |
|
102 | - 'default_subnav_slug' => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
100 | + 'position' => apply_filters('wpinv_bp_nav_position', wpinv_get_option('wpinv_menu_position', 91), $slug), |
|
101 | + 'screen_function' => array($this, 'display_current_tab'), |
|
102 | + 'default_subnav_slug' => apply_filters('getpaid_default_tab', 'gp-edit-address'), |
|
103 | 103 | 'show_for_displayed_user' => false, |
104 | 104 | 'item_css_id' => $this->id, |
105 | 105 | 'parent_url' => $user_domain, |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | ); |
108 | 108 | |
109 | 109 | // Add the subnav items to the payments nav item if we are using a theme that supports this. |
110 | - foreach ( getpaid_get_user_content_tabs() as $_slug => $tab ) { |
|
110 | + foreach (getpaid_get_user_content_tabs() as $_slug => $tab) { |
|
111 | 111 | |
112 | 112 | $sub_nav[] = array( |
113 | 113 | 'name' => $tab['label'], |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | 'parent_url' => $payments_link, |
116 | 116 | 'parent_slug' => $slug, |
117 | 117 | 'position' => 10, |
118 | - 'screen_function' => function() use ( $tab ) { |
|
118 | + 'screen_function' => function() use ($tab) { |
|
119 | 119 | $GLOBALS['getpaid_bp_current_tab'] = $tab; |
120 | 120 | $this->display_current_tab(); |
121 | 121 | }, |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | |
126 | 126 | } |
127 | 127 | |
128 | - parent::setup_nav( $main_nav, $sub_nav ); |
|
128 | + parent::setup_nav($main_nav, $sub_nav); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -139,36 +139,36 @@ discard block |
||
139 | 139 | * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a |
140 | 140 | * description. |
141 | 141 | */ |
142 | - public function setup_admin_bar( $wp_admin_nav = array() ) { |
|
142 | + public function setup_admin_bar($wp_admin_nav = array()) { |
|
143 | 143 | |
144 | 144 | // Menus for logged in user. |
145 | - if ( is_user_logged_in() ) { |
|
145 | + if (is_user_logged_in()) { |
|
146 | 146 | |
147 | 147 | // Setup the logged in user variables. |
148 | - $payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' ); |
|
148 | + $payments_link = trailingslashit(bp_loggedin_user_domain() . 'getpaid/'); |
|
149 | 149 | |
150 | 150 | // Add the "Payments" sub menu. |
151 | 151 | $wp_admin_nav[] = array( |
152 | 152 | 'parent' => buddypress()->my_account_menu_id, |
153 | 153 | 'id' => 'my-account-getpaid', |
154 | - 'title' => _x( 'Billing', 'BuddyPress my account payments sub nav', 'invoicing' ), |
|
155 | - 'href' => $payments_link . apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
154 | + 'title' => _x('Billing', 'BuddyPress my account payments sub nav', 'invoicing'), |
|
155 | + 'href' => $payments_link . apply_filters('getpaid_default_tab', 'gp-edit-address'), |
|
156 | 156 | ); |
157 | 157 | |
158 | - foreach ( getpaid_get_user_content_tabs() as $slug => $tab ) { |
|
158 | + foreach (getpaid_get_user_content_tabs() as $slug => $tab) { |
|
159 | 159 | |
160 | 160 | $wp_admin_nav[] = array( |
161 | 161 | 'parent' => 'my-account-getpaid', |
162 | 162 | 'id' => 'my-account-getpaid' . $slug, |
163 | 163 | 'title' => $tab['label'], |
164 | - 'href' => trailingslashit( $payments_link . $slug ), |
|
164 | + 'href' => trailingslashit($payments_link . $slug), |
|
165 | 165 | 'position' => 20, |
166 | 166 | ); |
167 | 167 | |
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
171 | - parent::setup_admin_bar( $wp_admin_nav ); |
|
171 | + parent::setup_admin_bar($wp_admin_nav); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | public function get_current_tab() { |
180 | 180 | global $getpaid_bp_current_tab; |
181 | 181 | |
182 | - if ( empty( $getpaid_bp_current_tab ) ) { |
|
182 | + if (empty($getpaid_bp_current_tab)) { |
|
183 | 183 | return array( |
184 | - 'label' => __( 'Invoices', 'invoicing' ), |
|
184 | + 'label' => __('Invoices', 'invoicing'), |
|
185 | 185 | 'content' => '[wpinv_history]', |
186 | 186 | 'icon' => 'fas fa-file-invoice', |
187 | 187 | ); |
@@ -197,10 +197,10 @@ discard block |
||
197 | 197 | */ |
198 | 198 | public function display_current_tab() { |
199 | 199 | |
200 | - add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) ); |
|
201 | - $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ); |
|
200 | + add_action('bp_template_content', array($this, 'handle_display_current_tab')); |
|
201 | + $template = apply_filters('bp_core_template_plugin', 'members/single/plugins'); |
|
202 | 202 | |
203 | - bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) ); |
|
203 | + bp_core_load_template(apply_filters('wpinv_bp_core_template_plugin', $template)); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | * @since 2.1.5 |
210 | 210 | */ |
211 | 211 | public function handle_display_current_tab() { |
212 | - getpaid_prepare_user_content_tab( $this->get_current_tab() ); |
|
212 | + getpaid_prepare_user_content_tab($this->get_current_tab()); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | } |
@@ -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 Legacy Payment Gateway class. |
@@ -28,8 +28,8 @@ discard block |
||
28 | 28 | * @param WPInv_Invoice $invoice Invoice. |
29 | 29 | * @return string |
30 | 30 | */ |
31 | - public function get_api_url( $invoice ) { |
|
32 | - return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
|
31 | + public function get_api_url($invoice) { |
|
32 | + return $this->is_sandbox($invoice) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -40,48 +40,48 @@ discard block |
||
40 | 40 | * @param WPInv_Invoice $invoice Invoice. |
41 | 41 | * @return stdClass|WP_Error |
42 | 42 | */ |
43 | - public function post( $post, $invoice ) { |
|
43 | + public function post($post, $invoice) { |
|
44 | 44 | |
45 | - $url = $this->get_api_url( $invoice ); |
|
45 | + $url = $this->get_api_url($invoice); |
|
46 | 46 | $response = wp_remote_post( |
47 | 47 | $url, |
48 | 48 | array( |
49 | 49 | 'headers' => array( |
50 | 50 | 'Content-Type' => 'application/json; charset=utf-8', |
51 | 51 | ), |
52 | - 'body' => json_encode( $post ), |
|
52 | + 'body' => json_encode($post), |
|
53 | 53 | 'method' => 'POST', |
54 | 54 | ) |
55 | 55 | ); |
56 | 56 | |
57 | - if ( is_wp_error( $response ) ) { |
|
57 | + if (is_wp_error($response)) { |
|
58 | 58 | return $response; |
59 | 59 | } |
60 | 60 | |
61 | - $response = wp_unslash( wp_remote_retrieve_body( $response ) ); |
|
62 | - $response = preg_replace( '/\xEF\xBB\xBF/', '', $response ); // https://community.developer.authorize.net/t5/Integration-and-Testing/JSON-issues/td-p/48851 |
|
63 | - $response = json_decode( $response ); |
|
61 | + $response = wp_unslash(wp_remote_retrieve_body($response)); |
|
62 | + $response = preg_replace('/\xEF\xBB\xBF/', '', $response); // https://community.developer.authorize.net/t5/Integration-and-Testing/JSON-issues/td-p/48851 |
|
63 | + $response = json_decode($response); |
|
64 | 64 | |
65 | - if ( empty( $response ) ) { |
|
66 | - return new WP_Error( 'invalid_reponse', __( 'Invalid gateway response', 'invoicing' ) ); |
|
65 | + if (empty($response)) { |
|
66 | + return new WP_Error('invalid_reponse', __('Invalid gateway response', 'invoicing')); |
|
67 | 67 | } |
68 | 68 | |
69 | - if ( $response->messages->resultCode == 'Error' ) { |
|
69 | + if ($response->messages->resultCode == 'Error') { |
|
70 | 70 | |
71 | - if ( $this->is_sandbox( $invoice ) ) { |
|
72 | - wpinv_error_log( $response ); |
|
71 | + if ($this->is_sandbox($invoice)) { |
|
72 | + wpinv_error_log($response); |
|
73 | 73 | } |
74 | 74 | |
75 | - if ( $response->messages->message[0]->code == 'E00039' && ! empty( $response->customerProfileId ) && ! empty( $response->customerPaymentProfileId ) ) { |
|
76 | - return new WP_Error( 'dup_payment_profile', $response->customerProfileId . '.' . $response->customerPaymentProfileId ); |
|
75 | + if ($response->messages->message[0]->code == 'E00039' && !empty($response->customerProfileId) && !empty($response->customerPaymentProfileId)) { |
|
76 | + return new WP_Error('dup_payment_profile', $response->customerProfileId . '.' . $response->customerPaymentProfileId); |
|
77 | 77 | } |
78 | 78 | |
79 | - if ( ! empty( $response->transactionResponse ) && ! empty( $response->transactionResponse->errors ) ) { |
|
79 | + if (!empty($response->transactionResponse) && !empty($response->transactionResponse->errors)) { |
|
80 | 80 | $error = $response->transactionResponse->errors[0]; |
81 | - return new WP_Error( $error->errorCode, $error->errorText ); |
|
81 | + return new WP_Error($error->errorCode, $error->errorText); |
|
82 | 82 | } |
83 | 83 | |
84 | - return new WP_Error( $response->messages->message[0]->code, $response->messages->message[0]->text ); |
|
84 | + return new WP_Error($response->messages->message[0]->code, $response->messages->message[0]->text); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | return $response; |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | public function get_auth_params() { |
98 | 98 | |
99 | 99 | return array( |
100 | - 'name' => $this->get_option( 'login_id' ), |
|
101 | - 'transactionKey' => $this->get_option( 'transaction_key' ), |
|
100 | + 'name' => $this->get_option('login_id'), |
|
101 | + 'transactionKey' => $this->get_option('transaction_key'), |
|
102 | 102 | ); |
103 | 103 | |
104 | 104 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @param WPInv_Subscription $subscription Subscription. |
111 | 111 | * @param WPInv_Invoice $invoice Invoice. |
112 | 112 | */ |
113 | - public function cancel_subscription( $subscription, $invoice ) { |
|
113 | + public function cancel_subscription($subscription, $invoice) { |
|
114 | 114 | |
115 | 115 | // Backwards compatibility. New version do not use authorize.net subscriptions. |
116 | 116 | $this->post( |
@@ -135,38 +135,38 @@ discard block |
||
135 | 135 | $this->maybe_process_old_ipn(); |
136 | 136 | |
137 | 137 | // Validate the IPN. |
138 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
139 | - wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) ); |
|
138 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
139 | + wp_die('Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array('response' => 200)); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | // Event type. |
143 | - $posted = json_decode( file_get_contents( 'php://input' ) ); |
|
144 | - if ( empty( $posted ) ) { |
|
145 | - wp_die( 'Invalid JSON', 'Authorize.NET IPN', array( 'response' => 200 ) ); |
|
143 | + $posted = json_decode(file_get_contents('php://input')); |
|
144 | + if (empty($posted)) { |
|
145 | + wp_die('Invalid JSON', 'Authorize.NET IPN', array('response' => 200)); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | // Process the IPN. |
149 | - $posted = (object) wp_unslash( $posted ); |
|
149 | + $posted = (object) wp_unslash($posted); |
|
150 | 150 | |
151 | 151 | // Process refunds. |
152 | - if ( 'net.authorize.payment.refund.created' == $posted->eventType ) { |
|
153 | - $invoice = new WPInv_Invoice( $posted->payload->merchantReferenceId ); |
|
154 | - $this->validate_ipn_invoice( $invoice, $posted->payload ); |
|
152 | + if ('net.authorize.payment.refund.created' == $posted->eventType) { |
|
153 | + $invoice = new WPInv_Invoice($posted->payload->merchantReferenceId); |
|
154 | + $this->validate_ipn_invoice($invoice, $posted->payload); |
|
155 | 155 | $invoice->refund(); |
156 | 156 | } |
157 | 157 | |
158 | 158 | // Held funds approved. |
159 | - if ( 'net.authorize.payment.fraud.approved' == $posted->eventType ) { |
|
160 | - $invoice = new WPInv_Invoice( $posted->payload->id ); |
|
161 | - $this->validate_ipn_invoice( $invoice, $posted->payload ); |
|
162 | - $invoice->mark_paid( false, __( 'Payment released', 'invoicing' ) ); |
|
159 | + if ('net.authorize.payment.fraud.approved' == $posted->eventType) { |
|
160 | + $invoice = new WPInv_Invoice($posted->payload->id); |
|
161 | + $this->validate_ipn_invoice($invoice, $posted->payload); |
|
162 | + $invoice->mark_paid(false, __('Payment released', 'invoicing')); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | // Held funds declined. |
166 | - if ( 'net.authorize.payment.fraud.declined' == $posted->eventType ) { |
|
167 | - $invoice = new WPInv_Invoice( $posted->payload->id ); |
|
168 | - $this->validate_ipn_invoice( $invoice, $posted->payload ); |
|
169 | - $invoice->set_status( 'wpi-failed', __( 'Payment declined', 'invoicing' ) ); |
|
166 | + if ('net.authorize.payment.fraud.declined' == $posted->eventType) { |
|
167 | + $invoice = new WPInv_Invoice($posted->payload->id); |
|
168 | + $this->validate_ipn_invoice($invoice, $posted->payload); |
|
169 | + $invoice->set_status('wpi-failed', __('Payment declined', 'invoicing')); |
|
170 | 170 | $invoice->save(); |
171 | 171 | } |
172 | 172 | |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | * @param object $payload |
182 | 182 | * @return void |
183 | 183 | */ |
184 | - public function validate_ipn_invoice( $invoice, $payload ) { |
|
185 | - if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) { |
|
184 | + public function validate_ipn_invoice($invoice, $payload) { |
|
185 | + if (!$invoice->exists() || $payload->id != $invoice->get_transaction_id()) { |
|
186 | 186 | exit; |
187 | 187 | } |
188 | 188 | } |
@@ -194,32 +194,32 @@ discard block |
||
194 | 194 | */ |
195 | 195 | public function maybe_process_old_ipn() { |
196 | 196 | |
197 | - $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
197 | + $data = wp_kses_post_deep(wp_unslash($_POST)); |
|
198 | 198 | |
199 | 199 | // Only process subscriptions subscriptions. |
200 | - if ( empty( $data['x_subscription_id'] ) ) { |
|
200 | + if (empty($data['x_subscription_id'])) { |
|
201 | 201 | return; |
202 | 202 | } |
203 | 203 | |
204 | 204 | // Check validity. |
205 | - $this->validate_old_ipn_signature( $data ); |
|
205 | + $this->validate_old_ipn_signature($data); |
|
206 | 206 | |
207 | 207 | // Fetch the associated subscription. |
208 | - $subscription_id = WPInv_Subscription::get_subscription_id_by_field( $data['x_subscription_id'] ); |
|
209 | - $subscription = new WPInv_Subscription( $subscription_id ); |
|
208 | + $subscription_id = WPInv_Subscription::get_subscription_id_by_field($data['x_subscription_id']); |
|
209 | + $subscription = new WPInv_Subscription($subscription_id); |
|
210 | 210 | |
211 | 211 | // Abort if it is missing or completed. |
212 | - if ( ! $subscription->get_id() || $subscription->has_status( 'completed' ) ) { |
|
212 | + if (!$subscription->get_id() || $subscription->has_status('completed')) { |
|
213 | 213 | return; |
214 | 214 | } |
215 | 215 | |
216 | 216 | // Payment status. |
217 | - if ( 1 == $data['x_response_code'] ) { |
|
217 | + if (1 == $data['x_response_code']) { |
|
218 | 218 | |
219 | 219 | // Renew the subscription. |
220 | 220 | $subscription->add_payment( |
221 | 221 | array( |
222 | - 'transaction_id' => sanitize_text_field( $data['x_trans_id'] ), |
|
222 | + 'transaction_id' => sanitize_text_field($data['x_trans_id']), |
|
223 | 223 | 'gateway' => $this->id, |
224 | 224 | ) |
225 | 225 | ); |
@@ -238,17 +238,17 @@ discard block |
||
238 | 238 | * |
239 | 239 | * @param array $posted |
240 | 240 | */ |
241 | - public function validate_old_ipn_signature( $posted ) { |
|
241 | + public function validate_old_ipn_signature($posted) { |
|
242 | 242 | |
243 | - $signature = $this->get_option( 'signature_key' ); |
|
244 | - if ( ! empty( $signature ) ) { |
|
245 | - $login_id = $this->get_option( 'login_id' ); |
|
246 | - $trans_id = wpinv_clean( $_POST['x_trans_id'] ); |
|
247 | - $amount = wpinv_clean( $_POST['x_amount'] ); |
|
248 | - $hash = hash_hmac( 'sha512', "^$login_id^$trans_id^$amount^", hex2bin( $signature ) ); |
|
243 | + $signature = $this->get_option('signature_key'); |
|
244 | + if (!empty($signature)) { |
|
245 | + $login_id = $this->get_option('login_id'); |
|
246 | + $trans_id = wpinv_clean($_POST['x_trans_id']); |
|
247 | + $amount = wpinv_clean($_POST['x_amount']); |
|
248 | + $hash = hash_hmac('sha512', "^$login_id^$trans_id^$amount^", hex2bin($signature)); |
|
249 | 249 | |
250 | - if ( ! hash_equals( $hash, $posted['x_SHA2_Hash'] ) ) { |
|
251 | - wpinv_error_log( $posted['x_SHA2_Hash'], "Invalid signature. Expected $hash" ); |
|
250 | + if (!hash_equals($hash, $posted['x_SHA2_Hash'])) { |
|
251 | + wpinv_error_log($posted['x_SHA2_Hash'], "Invalid signature. Expected $hash"); |
|
252 | 252 | exit; |
253 | 253 | } |
254 | 254 | } |
@@ -260,28 +260,28 @@ discard block |
||
260 | 260 | */ |
261 | 261 | public function validate_ipn() { |
262 | 262 | |
263 | - wpinv_error_log( 'Validating Authorize.NET IPN response' ); |
|
263 | + wpinv_error_log('Validating Authorize.NET IPN response'); |
|
264 | 264 | |
265 | - if ( empty( $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) { |
|
265 | + if (empty($_SERVER['HTTP_X_ANET_SIGNATURE'])) { |
|
266 | 266 | return false; |
267 | 267 | } |
268 | 268 | |
269 | - $signature = $this->get_option( 'signature_key' ); |
|
269 | + $signature = $this->get_option('signature_key'); |
|
270 | 270 | |
271 | - if ( empty( $signature ) ) { |
|
272 | - wpinv_error_log( 'Error: You have not set a signature key' ); |
|
271 | + if (empty($signature)) { |
|
272 | + wpinv_error_log('Error: You have not set a signature key'); |
|
273 | 273 | return false; |
274 | 274 | } |
275 | 275 | |
276 | - $hash = hash_hmac( 'sha512', file_get_contents( 'php://input' ), hex2bin( $signature ) ); |
|
276 | + $hash = hash_hmac('sha512', file_get_contents('php://input'), hex2bin($signature)); |
|
277 | 277 | |
278 | - if ( hash_equals( $hash, $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) { |
|
279 | - wpinv_error_log( 'Successfully validated the IPN' ); |
|
278 | + if (hash_equals($hash, $_SERVER['HTTP_X_ANET_SIGNATURE'])) { |
|
279 | + wpinv_error_log('Successfully validated the IPN'); |
|
280 | 280 | return true; |
281 | 281 | } |
282 | 282 | |
283 | - wpinv_error_log( 'IPN hash is not valid' ); |
|
284 | - wpinv_error_log( $_SERVER['HTTP_X_ANET_SIGNATURE'] ); |
|
283 | + wpinv_error_log('IPN hash is not valid'); |
|
284 | + wpinv_error_log($_SERVER['HTTP_X_ANET_SIGNATURE']); |
|
285 | 285 | return false; |
286 | 286 | |
287 | 287 | } |
@@ -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 | * Paypal Payment Gateway IPN handler class. |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @param GetPaid_Paypal_Gateway $gateway |
33 | 33 | */ |
34 | - public function __construct( $gateway ) { |
|
34 | + public function __construct($gateway) { |
|
35 | 35 | $this->gateway = $gateway; |
36 | 36 | $this->verify_ipn(); |
37 | 37 | } |
@@ -43,37 +43,37 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function verify_ipn() { |
45 | 45 | |
46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
46 | + wpinv_error_log('GetPaid PayPal IPN Handler', false); |
|
47 | 47 | |
48 | 48 | // Validate the IPN. |
49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
49 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
50 | + wp_die('PayPal IPN Request Failure', 500); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | // Process the IPN. |
54 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
54 | + $posted = wp_kses_post_deep(wp_unslash($_POST)); |
|
55 | + $invoice = $this->get_ipn_invoice($posted); |
|
56 | 56 | |
57 | 57 | // Abort if it was not paid by our gateway. |
58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
60 | - wp_die( 'Invoice not paid via PayPal', 200 ); |
|
58 | + if ($this->id != $invoice->get_gateway()) { |
|
59 | + wpinv_error_log('Aborting, Invoice was not paid via PayPal', false); |
|
60 | + wp_die('Invoice not paid via PayPal', 200); |
|
61 | 61 | } |
62 | 62 | |
63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
63 | + $posted['payment_status'] = isset($posted['payment_status']) ? sanitize_key(strtolower($posted['payment_status'])) : ''; |
|
64 | + $posted['txn_type'] = sanitize_key(strtolower($posted['txn_type'])); |
|
65 | 65 | |
66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
66 | + wpinv_error_log('Payment status:' . $posted['payment_status'], false); |
|
67 | + wpinv_error_log('IPN Type:' . $posted['txn_type'], false); |
|
68 | 68 | |
69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | - wpinv_error_log( 'Done processing IPN', false ); |
|
72 | - wp_die( 'Processed', 200 ); |
|
69 | + if (method_exists($this, 'ipn_txn_' . $posted['txn_type'])) { |
|
70 | + call_user_func(array($this, 'ipn_txn_' . $posted['txn_type']), $invoice, $posted); |
|
71 | + wpinv_error_log('Done processing IPN', false); |
|
72 | + wp_die('Processed', 200); |
|
73 | 73 | } |
74 | 74 | |
75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
75 | + wpinv_error_log('Aborting, Unsupported IPN type:' . $posted['txn_type'], false); |
|
76 | + wp_die('Unsupported IPN type', 200); |
|
77 | 77 | |
78 | 78 | } |
79 | 79 | |
@@ -83,21 +83,21 @@ discard block |
||
83 | 83 | * @param array $posted |
84 | 84 | * @return WPInv_Invoice |
85 | 85 | */ |
86 | - protected function get_ipn_invoice( $posted ) { |
|
86 | + protected function get_ipn_invoice($posted) { |
|
87 | 87 | |
88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
88 | + wpinv_error_log('Retrieving PayPal IPN Response Invoice', false); |
|
89 | 89 | |
90 | - if ( ! empty( $posted['custom'] ) ) { |
|
91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
90 | + if (!empty($posted['custom'])) { |
|
91 | + $invoice = new WPInv_Invoice($posted['custom']); |
|
92 | 92 | |
93 | - if ( $invoice->exists() ) { |
|
94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
93 | + if ($invoice->exists()) { |
|
94 | + wpinv_error_log('Found invoice #' . $invoice->get_number(), false); |
|
95 | 95 | return $invoice; |
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
99 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
100 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
99 | + wpinv_error_log('Could not retrieve the associated invoice.', false); |
|
100 | + wp_die('Could not retrieve the associated invoice.', 200); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -105,14 +105,14 @@ discard block |
||
105 | 105 | */ |
106 | 106 | protected function validate_ipn() { |
107 | 107 | |
108 | - wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
108 | + wpinv_error_log('Validating PayPal IPN response', false); |
|
109 | 109 | |
110 | 110 | // Retrieve the associated invoice. |
111 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
112 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
111 | + $posted = wp_kses_post_deep(wp_unslash($_POST)); |
|
112 | + $invoice = $this->get_ipn_invoice($posted); |
|
113 | 113 | |
114 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
115 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
114 | + if ($this->gateway->is_sandbox($invoice)) { |
|
115 | + wpinv_error_log($posted, 'Invoice was processed in sandbox hence logging the posted data', false); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | // Validate the IPN. |
@@ -129,20 +129,20 @@ discard block |
||
129 | 129 | ); |
130 | 130 | |
131 | 131 | // Post back to get a response. |
132 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
132 | + $response = wp_safe_remote_post($this->gateway->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params); |
|
133 | 133 | |
134 | 134 | // Check to see if the request was valid. |
135 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
136 | - wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
135 | + if (!is_wp_error($response) && $response['response']['code'] < 300 && strstr($response['body'], 'VERIFIED')) { |
|
136 | + wpinv_error_log('Received valid response from PayPal IPN: ' . $response['body'], false); |
|
137 | 137 | return true; |
138 | 138 | } |
139 | 139 | |
140 | - if ( is_wp_error( $response ) ) { |
|
141 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
140 | + if (is_wp_error($response)) { |
|
141 | + wpinv_error_log($response->get_error_message(), 'Received invalid response from PayPal IPN'); |
|
142 | 142 | return false; |
143 | 143 | } |
144 | 144 | |
145 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
145 | + wpinv_error_log($response['body'], 'Received invalid response from PayPal IPN'); |
|
146 | 146 | return false; |
147 | 147 | |
148 | 148 | } |
@@ -153,17 +153,17 @@ discard block |
||
153 | 153 | * @param WPInv_Invoice $invoice Invoice object. |
154 | 154 | * @param string $currency currency to validate. |
155 | 155 | */ |
156 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
156 | + protected function validate_ipn_currency($invoice, $currency) { |
|
157 | 157 | |
158 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
158 | + if (strtolower($invoice->get_currency()) !== strtolower($currency)) { |
|
159 | 159 | |
160 | 160 | /* translators: %s: currency code. */ |
161 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
161 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal currencies do not match (code %s).', 'invoicing'), $currency)); |
|
162 | 162 | |
163 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
163 | + wpinv_error_log("Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true); |
|
164 | 164 | } |
165 | 165 | |
166 | - wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
166 | + wpinv_error_log($currency, 'Validated IPN Currency', false); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -172,16 +172,16 @@ discard block |
||
172 | 172 | * @param WPInv_Invoice $invoice Invoice object. |
173 | 173 | * @param float $amount amount to validate. |
174 | 174 | */ |
175 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
176 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
175 | + protected function validate_ipn_amount($invoice, $amount) { |
|
176 | + if (number_format($invoice->get_total(), 2, '.', '') !== number_format($amount, 2, '.', '')) { |
|
177 | 177 | |
178 | 178 | /* translators: %s: Amount. */ |
179 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
179 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal amounts do not match (gross %s).', 'invoicing'), $amount)); |
|
180 | 180 | |
181 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
181 | + wpinv_error_log("Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true); |
|
182 | 182 | } |
183 | 183 | |
184 | - wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
184 | + wpinv_error_log($amount, 'Validated IPN Amount', false); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
@@ -190,19 +190,19 @@ discard block |
||
190 | 190 | * @param WPInv_Invoice $invoice Invoice object. |
191 | 191 | * @param string $receiver_email Email to validate. |
192 | 192 | */ |
193 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
194 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
193 | + protected function validate_ipn_receiver_email($invoice, $receiver_email) { |
|
194 | + $paypal_email = wpinv_get_option('paypal_email'); |
|
195 | 195 | |
196 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
197 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
196 | + if (strcasecmp(trim($receiver_email), trim($paypal_email)) !== 0) { |
|
197 | + wpinv_record_gateway_error('IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}"); |
|
198 | 198 | |
199 | 199 | /* translators: %s: email address . */ |
200 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
200 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal IPN response from a different email address (%s).', 'invoicing'), $receiver_email)); |
|
201 | 201 | |
202 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
202 | + return wpinv_error_log("IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true); |
|
203 | 203 | } |
204 | 204 | |
205 | - wpinv_error_log( 'Validated PayPal Email', false ); |
|
205 | + wpinv_error_log('Validated PayPal Email', false); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -211,70 +211,70 @@ discard block |
||
211 | 211 | * @param WPInv_Invoice $invoice Invoice object. |
212 | 212 | * @param array $posted Posted data. |
213 | 213 | */ |
214 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
214 | + protected function ipn_txn_web_accept($invoice, $posted) { |
|
215 | 215 | |
216 | 216 | // Collect payment details |
217 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
218 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
217 | + $payment_status = strtolower($posted['payment_status']); |
|
218 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
219 | 219 | |
220 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
221 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
220 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
221 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
222 | 222 | |
223 | 223 | // Update the transaction id. |
224 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
225 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
224 | + if (!empty($posted['txn_id'])) { |
|
225 | + $invoice->set_transaction_id(wpinv_clean($posted['txn_id'])); |
|
226 | 226 | $invoice->save(); |
227 | 227 | } |
228 | 228 | |
229 | - $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
229 | + $invoice->add_system_note(__('Processing invoice IPN', 'invoicing')); |
|
230 | 230 | |
231 | 231 | // Process a refund. |
232 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
232 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
233 | 233 | |
234 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
234 | + update_post_meta($invoice->get_id(), 'refunded_remotely', 1); |
|
235 | 235 | |
236 | - if ( ! $invoice->is_refunded() ) { |
|
237 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
236 | + if (!$invoice->is_refunded()) { |
|
237 | + $invoice->update_status('wpi-refunded', $posted['reason_code']); |
|
238 | 238 | } |
239 | 239 | |
240 | - return wpinv_error_log( $posted['reason_code'], false ); |
|
240 | + return wpinv_error_log($posted['reason_code'], false); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | // Process payments. |
244 | - if ( $payment_status == 'completed' ) { |
|
244 | + if ($payment_status == 'completed') { |
|
245 | 245 | |
246 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
247 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
246 | + if ($invoice->is_paid() && 'wpi_processing' != $invoice->get_status()) { |
|
247 | + return wpinv_error_log('Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false); |
|
248 | 248 | } |
249 | 249 | |
250 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
250 | + $this->validate_ipn_amount($invoice, $posted['mc_gross']); |
|
251 | 251 | |
252 | 252 | $note = ''; |
253 | 253 | |
254 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
255 | - $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
254 | + if (!empty($posted['mc_fee'])) { |
|
255 | + $note = sprintf(__('PayPal Transaction Fee %s.', 'invoicing'), sanitize_text_field($posted['mc_fee'])); |
|
256 | 256 | } |
257 | 257 | |
258 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
259 | - $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
258 | + if (!empty($posted['payer_status'])) { |
|
259 | + $note = ' ' . sprintf(__('Buyer status %s.', 'invoicing'), sanitize_text_field($posted['payer_status'])); |
|
260 | 260 | } |
261 | 261 | |
262 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
263 | - return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
262 | + $invoice->mark_paid((!empty($posted['txn_id']) ? sanitize_text_field($posted['txn_id']) : ''), trim($note)); |
|
263 | + return wpinv_error_log('Invoice marked as paid.', false); |
|
264 | 264 | |
265 | 265 | } |
266 | 266 | |
267 | 267 | // Pending payments. |
268 | - if ( $payment_status == 'pending' ) { |
|
268 | + if ($payment_status == 'pending') { |
|
269 | 269 | |
270 | 270 | /* translators: %s: pending reason. */ |
271 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
271 | + $invoice->update_status('wpi-onhold', sprintf(__('Payment pending (%s).', 'invoicing'), $posted['pending_reason'])); |
|
272 | 272 | |
273 | - return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
273 | + return wpinv_error_log('Invoice marked as "payment held".', false); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /* translators: %s: payment status. */ |
277 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
277 | + $invoice->update_status('wpi-failed', sprintf(__('Payment %s via IPN.', 'invoicing'), sanitize_text_field($posted['payment_status']))); |
|
278 | 278 | |
279 | 279 | } |
280 | 280 | |
@@ -284,8 +284,8 @@ discard block |
||
284 | 284 | * @param WPInv_Invoice $invoice Invoice object. |
285 | 285 | * @param array $posted Posted data. |
286 | 286 | */ |
287 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
288 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
287 | + protected function ipn_txn_cart($invoice, $posted) { |
|
288 | + $this->ipn_txn_web_accept($invoice, $posted); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
@@ -294,43 +294,43 @@ discard block |
||
294 | 294 | * @param WPInv_Invoice $invoice Invoice object. |
295 | 295 | * @param array $posted Posted data. |
296 | 296 | */ |
297 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
297 | + protected function ipn_txn_subscr_signup($invoice, $posted) { |
|
298 | 298 | |
299 | - wpinv_error_log( 'Processing subscription signup', false ); |
|
299 | + wpinv_error_log('Processing subscription signup', false); |
|
300 | 300 | |
301 | 301 | // Make sure the invoice has a subscription. |
302 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
302 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
303 | 303 | |
304 | - if ( empty( $subscription ) ) { |
|
305 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
304 | + if (empty($subscription)) { |
|
305 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
306 | 306 | } |
307 | 307 | |
308 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
308 | + wpinv_error_log('Found subscription #' . $subscription->get_id(), false); |
|
309 | 309 | |
310 | 310 | // Validate the IPN. |
311 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
312 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
313 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
311 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
312 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
313 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
314 | 314 | |
315 | 315 | // Activate the subscription. |
316 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
317 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
318 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
319 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
316 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
317 | + $subscription->set_date_created(current_time('mysql')); |
|
318 | + $subscription->set_expiration(date('Y-m-d H:i:s', (current_time('timestamp') + $duration))); |
|
319 | + $subscription->set_profile_id(sanitize_text_field($posted['subscr_id'])); |
|
320 | 320 | $subscription->activate(); |
321 | 321 | |
322 | 322 | // Set the transaction id. |
323 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
324 | - $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
325 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
323 | + if (!empty($posted['txn_id'])) { |
|
324 | + $invoice->add_note(sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
325 | + $invoice->set_transaction_id($posted['txn_id']); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | // Update the payment status. |
329 | 329 | $invoice->mark_paid(); |
330 | 330 | |
331 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
331 | + $invoice->add_note(sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
332 | 332 | |
333 | - wpinv_error_log( 'Subscription started.', false ); |
|
333 | + wpinv_error_log('Subscription started.', false); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
@@ -339,45 +339,45 @@ discard block |
||
339 | 339 | * @param WPInv_Invoice $invoice Invoice object. |
340 | 340 | * @param array $posted Posted data. |
341 | 341 | */ |
342 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
342 | + protected function ipn_txn_subscr_payment($invoice, $posted) { |
|
343 | 343 | |
344 | 344 | // Make sure the invoice has a subscription. |
345 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
345 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
346 | 346 | |
347 | - if ( empty( $subscription ) ) { |
|
348 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
347 | + if (empty($subscription)) { |
|
348 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
349 | 349 | } |
350 | 350 | |
351 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
351 | + wpinv_error_log('Found subscription #' . $subscription->get_id(), false); |
|
352 | 352 | |
353 | 353 | // PayPal sends a subscr_payment for the first payment too. |
354 | - $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
355 | - $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
356 | - $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
357 | - $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
358 | - $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
359 | - $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
354 | + $date_completed = getpaid_format_date($invoice->get_date_completed()); |
|
355 | + $date_created = getpaid_format_date($invoice->get_date_created()); |
|
356 | + $today_date = getpaid_format_date(current_time('mysql')); |
|
357 | + $payment_date = getpaid_format_date($posted['payment_date']); |
|
358 | + $subscribe_date = getpaid_format_date($subscription->get_date_created()); |
|
359 | + $dates = array_filter(compact('date_completed', 'date_created', 'subscribe_date')); |
|
360 | 360 | |
361 | - foreach ( $dates as $date ) { |
|
361 | + foreach ($dates as $date) { |
|
362 | 362 | |
363 | - if ( $date !== $today_date && $date !== $payment_date ) { |
|
363 | + if ($date !== $today_date && $date !== $payment_date) { |
|
364 | 364 | continue; |
365 | 365 | } |
366 | 366 | |
367 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
368 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
369 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
367 | + if (!empty($posted['txn_id'])) { |
|
368 | + $invoice->set_transaction_id(sanitize_text_field($posted['txn_id'])); |
|
369 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), sanitize_text_field($posted['txn_id'])), false, false, true); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | return $invoice->mark_paid(); |
373 | 373 | |
374 | 374 | } |
375 | 375 | |
376 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
376 | + wpinv_error_log('Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false); |
|
377 | 377 | |
378 | 378 | // Abort if the payment is already recorded. |
379 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
380 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false ); |
|
379 | + if (wpinv_get_id_by_transaction_id($posted['txn_id'])) { |
|
380 | + return wpinv_error_log('Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | $args = array( |
@@ -385,17 +385,17 @@ discard block |
||
385 | 385 | 'gateway' => $this->id, |
386 | 386 | ); |
387 | 387 | |
388 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
388 | + $invoice = wpinv_get_invoice($subscription->add_payment($args)); |
|
389 | 389 | |
390 | - if ( empty( $invoice ) ) { |
|
390 | + if (empty($invoice)) { |
|
391 | 391 | return; |
392 | 392 | } |
393 | 393 | |
394 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
395 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
394 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
395 | + $invoice->add_note(wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
396 | 396 | |
397 | 397 | $subscription->renew(); |
398 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
398 | + wpinv_error_log('Subscription renewed.', false); |
|
399 | 399 | |
400 | 400 | } |
401 | 401 | |
@@ -404,18 +404,18 @@ discard block |
||
404 | 404 | * |
405 | 405 | * @param WPInv_Invoice $invoice Invoice object. |
406 | 406 | */ |
407 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
407 | + protected function ipn_txn_subscr_cancel($invoice) { |
|
408 | 408 | |
409 | 409 | // Make sure the invoice has a subscription. |
410 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
410 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
411 | 411 | |
412 | - if ( empty( $subscription ) ) { |
|
413 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
412 | + if (empty($subscription)) { |
|
413 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
414 | 414 | } |
415 | 415 | |
416 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
416 | + wpinv_error_log('Processing subscription cancellation for the invoice ' . $invoice->get_id(), false); |
|
417 | 417 | $subscription->cancel(); |
418 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
418 | + wpinv_error_log('Subscription cancelled.', false); |
|
419 | 419 | |
420 | 420 | } |
421 | 421 | |
@@ -425,18 +425,18 @@ discard block |
||
425 | 425 | * @param WPInv_Invoice $invoice Invoice object. |
426 | 426 | * @param array $posted Posted data. |
427 | 427 | */ |
428 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
428 | + protected function ipn_txn_subscr_eot($invoice) { |
|
429 | 429 | |
430 | 430 | // Make sure the invoice has a subscription. |
431 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
431 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
432 | 432 | |
433 | - if ( empty( $subscription ) ) { |
|
434 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
433 | + if (empty($subscription)) { |
|
434 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
435 | 435 | } |
436 | 436 | |
437 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
437 | + wpinv_error_log('Processing subscription end of life for the invoice ' . $invoice->get_id(), false); |
|
438 | 438 | $subscription->complete(); |
439 | - wpinv_error_log( 'Subscription completed.', false ); |
|
439 | + wpinv_error_log('Subscription completed.', false); |
|
440 | 440 | |
441 | 441 | } |
442 | 442 | |
@@ -446,18 +446,18 @@ discard block |
||
446 | 446 | * @param WPInv_Invoice $invoice Invoice object. |
447 | 447 | * @param array $posted Posted data. |
448 | 448 | */ |
449 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
449 | + protected function ipn_txn_subscr_failed($invoice) { |
|
450 | 450 | |
451 | 451 | // Make sure the invoice has a subscription. |
452 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
452 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
453 | 453 | |
454 | - if ( empty( $subscription ) ) { |
|
455 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
454 | + if (empty($subscription)) { |
|
455 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
456 | 456 | } |
457 | 457 | |
458 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
458 | + wpinv_error_log('Processing subscription payment failure for the invoice ' . $invoice->get_id(), false); |
|
459 | 459 | $subscription->failing(); |
460 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
460 | + wpinv_error_log('Subscription marked as failing.', false); |
|
461 | 461 | |
462 | 462 | } |
463 | 463 | |
@@ -467,18 +467,18 @@ discard block |
||
467 | 467 | * @param WPInv_Invoice $invoice Invoice object. |
468 | 468 | * @param array $posted Posted data. |
469 | 469 | */ |
470 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
470 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment($invoice) { |
|
471 | 471 | |
472 | 472 | // Make sure the invoice has a subscription. |
473 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
473 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
474 | 474 | |
475 | - if ( empty( $subscription ) ) { |
|
476 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
475 | + if (empty($subscription)) { |
|
476 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
477 | 477 | } |
478 | 478 | |
479 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
479 | + wpinv_error_log('Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false); |
|
480 | 480 | $subscription->cancel(); |
481 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
481 | + wpinv_error_log('Subscription cancelled.', false); |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | } |